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


2 Answers 2


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.

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

It is work for me.

public void BuildNoRecords(GridView gridView, DataSet ds)
  try {
   if (ds.Tables(0).Rows.Count == 0) {
   gridView.DataSource = ds;
   int columnCount = gridView.Rows(0).Cells.Count;
   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) {

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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