SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

share|improve this question

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.

share|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. – Daniel Ziga May 3 '12 at 8:16
Thanks, i use this property but don't show header – ar.gorgin May 3 '12 at 8:24
up vote 0 down vote accepted

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

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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