I have a webpart with SPGridView. I created column dynamic.
This works fine when I have data, but when no rows are returned then I just get a blank spot where the grid should be.
These 3 members are used to handle EmptyData in the SPGridView.
Also check out this link for more info
Update 1: If you just want to show the headers even though there are no data, use the ShowHeaderWhenEmpty property.
Update 2: Check the list of properties and members for the SPGridView here.
It is work for me.
public void BuildNoRecords(GridView gridView, DataSet ds)
{
try {
if (ds.Tables(0).Rows.Count == 0) {
ds.Tables(0).Rows.Add(ds.Tables(0).NewRow());
gridView.DataSource = ds;
gridView.DataBind();
int columnCount = gridView.Rows(0).Cells.Count;
gridView.Rows(0).Cells.Clear();
gridView.Rows(0).Cells.Add(new TableCell());
gridView.Rows(0).Cells(0).ColumnSpan = columnCount;
gridView.Rows(0).Cells(0).Text = "No Records Found.";
}
} catch (Exception ex) {
}