Display text in DataGridView when there are no rows


Display text in DataGridView when there are no rows

   
if (dt.Rows.Count > 0)
                {
                    grid1.DataSource = dt;
                    grid1.DataBind();
                }
                else
                {
                    dt.Rows.Add(dt.NewRow());
                    grid1.DataSource = dt;
                    grid1.DataBind();
                    int totalcolums = grid1.Rows[0].Cells.Count;
                    grid1.Rows[0].Cells.Clear();
                    grid1.Rows[0].Cells.Add(new TableCell());
                    grid1.Rows[0].Cells[0].ColumnSpan = totalcolums;
                    grid1.Rows[0].Cells[0].Text = "No Data Found";
                }

0 comments:

Post a Comment