Computing.Net > Forums > Web Development > How to show GridViewData When Db is empty????

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Click here to start participating now! Also, check out the New User Guide.

How to show GridViewData When Db is empty????

Reply to Message Icon

Name: GirishC
Date: May 27, 2009 at 03:32:08 Pacific
OS: Windows XP
Subcategory: General
Comment:

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



Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More


Confirm close page and lo... Google analytics



Post Locked

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


Go to Web Development Forum Home


Sponsored links

Ads by Google


Results for: How to show GridViewData When Db is empty????

How to hyperlink in CMS www.computing.net/answers/webdevel/how-to-hyperlink-in-cms/4281.html

how to see the cpanel www.computing.net/answers/webdevel/how-to-see-the-cpanel-/3937.html

Videos On How To Protect Your Website www.computing.net/answers/webdevel/videos-on-how-to-protect-your-website/4135.html