Thursday, June 6, 2013

To show the GridView with no rows/data

Add the below code before binding the data to GridView
 if (ds.Tables[0].Rows.Count == 0)
        {
            ds.Tables[0].Rows.Add(ds.Tables[0].NewRow());
            grdview.DataSource = ds;
            grdview.DataBind();
            int columncount = grdview.Rows[0].Cells.Count;
            grdview.Rows[0].Cells.Clear();
            grdview.Rows[0].Cells.Add(new TableCell());
            grdview.Rows[0].Cells[0].ColumnSpan = columncount;
            grdview.Rows[0].Cells[0].Text = "No Records Found";
        }
        else
        {
            grdview.DataSource = ds.Tables[0];
            grdview.DataBind();
        }

No comments:

Post a Comment