Saturday, July 14, 2012

Display custom message when there are no records in GridView using C#

As the Title says Display Custom Message When there are No records to display in GridView can be seen as shown.....





   if (ds.Tables[0].Rows.Count > 0)
   {
       EmpGrid.DataSource = ds;
       EmpGrid.DataBind();
   }
   else
   {
       ds.Tables[0].Rows.Add(ds.Tables[0].NewRow());
       EmpGrid.DataSource = ds;
       EmpGrid.DataBind();

       int columncount = EmpGrid.Rows[0].Cells.Count;
       EmpGrid.Rows[0].Cells.Clear();
       EmpGrid.Rows[0].Cells.Add(new TableCell());
       EmpGrid.Rows[0].Cells[0].ColumnSpan = columncount;
       EmpGrid.Rows[0].Cells[0].Text =  
                      "<center>No Items To Display...!</center>";
   }       

No comments:

Post a Comment