0

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.

enter image description here

1

These 3 members are used to handle EmptyData in the SPGridView.

  1. EmptyDataRowStyle
  2. EmptyDataTemplate
  3. EmptyDataText

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.

| improve this answer | |
  • Thanks, but i want show header (Example listwebpart). – ar.gorgin May 3 '12 at 8:07
  • @ar.gorgin Please see my update. – user2536 May 3 '12 at 8:16
  • Thanks, i use this property but don't show header – ar.gorgin May 3 '12 at 8:24
0

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) {
}
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.