Binding Empty Row to GridView to Avoid Empty Data Template

private void LoadEmptyGrid(GridView GV,string DBO)
{
GV.DataBind();
if (GV.Rows.Count == 0)
{
DataTable dt = new DataTable();
dt = DataAccessLayer.Get(“SELECT * FROM “+DBO); // The schema information is copied   //No need to create data table definition programatically.                                                                       for (int i = 0; i < dt.Columns.Count; i++)                                                             dt.Columns[i].AllowDBNull = true;

if (dt.Rows.Count == 0)
dt.Rows.Add(dt.NewRow()); //This will add a blank row
GV.DataSourceID = string.Empty;
GV.DataSource = dt;
GV.DataBind();
}
}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s