Click here to Skip to main content
16,004,919 members
Please Sign up or sign in to vote.
1.44/5 (2 votes)
See more:
In my following code I want to skip showing Gridview when my dataset 'ds' has no rows(blank):

C#
GridView2.DataSource = ds;
GridView2.DataBind();
GridView2.Visible = true;


How to use 'If' condition here.
Posted

C#
IF(DS.tables[0].rows.count>0)
{
   gridview2.datasource=ds;
   gridview2.databind()
}
else
{
gridview2.visible=false;
gridview2.datasource=null;
 gridview2.databind()

}
 
Share this answer
 
v2
Use This code:

GridView2.DataSource = ds;

GridView2.Visible =false;

if(ds.Tables.COunt>0)

{

if(ds.Tables[0].Rows.Count>0)
{
GridView2.DataBind();
GridView2.Visible =true;
}

}
 
Share this answer
 

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