I have an ASP.NET 2.0 (C#) web app, and in it I have a gridview that gets its data from an oracle database.
I want to know how to check if the gridview is empty, and the do something.
I have already tried:
if(GridView.Rows.Count == 0)
{
// Do Something
}
but it doesn't work...
Any ideas?
Thank you.
HTML MarkupThe ShowHeaderWhenEmpty property of the GridView control is set to True so that even when there is no data, the GridView will display the Header row. The EmptyDataTemplate property has been specified with an Empty Message i.e. No records found which will be displayed when the GridView is empty.
To do that, we need to enable the Boolean property ShowHeaderWhenEmpty to True. Be sure you're using the ASP.NET 4.0 or later version to use this property. Also, we need to add the <EmptyDataTemplate></EmptyDataTemplate> property inside the grid view to display the message.
Your code should work. But only after GridView.DataBind() has been called. Generally I don't check the GridView it's self, but the datasource of the grid view.
DataTable data = DAL.getdata();
if (data.Rows.Count == 0)
{
ShowEmptyData();
}
else
{
Grid.DataSource = dt;
Grid.DataBind();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With