Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
How to show GridView Data When Database is empty??????
Hi All,
I am using the Gridview control to bind the database to Gridview.
---------------------------------------------------------------------------------
<asp:GridView ID="GV1" runat="server" style="top: 635px; left: 231px; position: absolute; height: 183px; width: 325px"
AutoGenerateColumns="False" BackColor="#DEBA84" BorderColor="#DEBA84"
BorderStyle="None" BorderWidth="1px" CellPadding="3" CellSpacing="2"
onrowediting="GV1_RowEditing" onrowupdating="GV1_RowUpdating" >
<RowStyle BackColor="#FFF7E7" ForeColor="#8C4510" />
<Columns>
<asp:TemplateField HeaderText="Roll No">
<ItemTemplate>
<asp:Label ID="lblRollNo" runat="server" Text='<%# Eval("RollNo")%>' Width="100px" ></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Absent Days">
<ItemTemplate>
<asp:Label ID="lblAbsentDays" runat="server" Text='<%# Eval("AbsentDays")%>' Width="100px" ></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtAbsentDays" runat="server" Text='<%# Eval("AbsentDays")%>' Width="100px" ></asp:TextBox >
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Present Days">
<ItemTemplate>
<asp:Label ID="lblPresentDays" runat="server" Text='<%# Eval("PresentDays") %>' Width="100px" ></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Average Presenty">
<ItemTemplate>
<asp:Label ID="lblAveragePresenty" runat="server" Text='<%# Eval("AveragePresenty")%>' Width="100px" ></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Set">
<ItemTemplate>
<a href='Default3.aspx?rno=<%# Eval("RollNo")%>&AbsentDays=<%# Eval("AbsentDays") %>'>Set
</ItemTemplate>
</asp:TemplateField>
<asp:CommandField ShowEditButton="true" />
</Columns>
<FooterStyle BackColor="#F7DFB5" ForeColor="#8C4510" />
<PagerStyle ForeColor="#8C4510" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#738A9C" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#A55129" Font-Bold="True" ForeColor="White" />
</asp:GridView>
---------------------------------------------------------------------------------Now when i connect the database & bind it to Gridview control (data in database initially empty) that time shows nothing. How to show empty gridview with only column name.
I am writting the code at page load.
---------------------------------------------------------------------------------
if (!Page.IsPostBack)
{MySqlConnection cnx = new MySqlConnection(cnnString);
MySqlDataAdapter adapter = new MySqlDataAdapter();
try
{
cnx.Open();
// Create a SQL command object
string cmdText = "SELECT * FROM presenty";
MySqlCommand cmd1 = new MySqlCommand(cmdText, cnx);// Create a fill a Dataset
DataSet ds = new DataSet();
adapter.SelectCommand = cmd1;
adapter.Fill(ds);// Bind the DataSet
GV1.DataSource = ds;
GV1.DataBind();
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
finally
{
cnx.Close();
}
}
---------------------------------------------------------------------------------Plz, guide me how we can show empty gridview with only column name.
Regards,
Girish

![]() |
Confirm close page and lo...
|
Google analytics
|

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |