Click here to Skip to main content
15,357,464 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all,

I need to show error message in Label if gridview is empty.

C#
if(GridView1.RowCount == 0)
{
   lblError.Text = "Record is empty";
}


Please need help. Thank you!
Posted
Comments
Member 10291409 1-Feb-14 18:51pm
   
<emptydatatemplate>Record is empty

Code Project - Frequently Asked Questions Series 1: The ASP.Net GridView[^] might help you out as well (for null values).
   
Try this one instead:
C#
if(GridView1.Rows.Count == 0)
{
   lblError.Text = "Record is empty";
}



This one is easier fyi:
XML
<asp:GridView ID="GridView1" runat="server" EmptyDataText="Record is empty" />


Regards,
Eduard
   
Comments
Aja wakim 4-Dec-11 4:39am
   
the 2nd one is better! thanks for the help!
Uday P.Singh 4-Dec-11 5:24am
   
5ed :)
[no name] 4-Dec-11 20:29pm
   
thanks
Monjurul Habib 4-Dec-11 6:15am
   
my 5!
[no name] 4-Dec-11 20:29pm
   
thanks
C#
<emptydatatemplate>Record is empty </emptydatatemplate>
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900