Reputation: 293
How can I show my controls even if my table columns are null using gridview? All I know is ShowHeaderWhenEmpty="true"
Upvotes: 4
Views: 86
Reputation: 538
If datasource of gridview is null, you can create a temporery datatable and assign it as a datasuource of gridview.
if (GridView1.DataSource == null)
{
DataTable dt = new DataTable();
dt.Columns.Add("Name");
DataRow dr = dt.NewRow();
dr[0] = "";
dt.Rows.Add(dr);
GridView1.DataSource=dt;
GridView1.DataBind();
}
Upvotes: 1
Reputation: 24
If your data is NULL then there is no data to show. In order to show the controls, you need to have data. I'd try to create a dummy row if the db returns null.
if(db.rows.count < 1)
{
//add a row with dummy values
}
Hope this helps.
Upvotes: 1