0

My gridview doesn't show anything because my database is null. How can I display even just the controls so I could start transacting? Is there a way to properly present the datagrid even if it's null? Maybe even just the columns of the table displaying?

1
  • This is a very broad question. Please include some code to show us the specific problem.
    – Jeroen
    Feb 20, 2014 at 7:36

2 Answers 2

1

use this ShowHeaderWhenEmpty="true"

<asp:GridView runat="server" ID="gv" ShowHeaderWhenEmpty="true">
</asp:GridView>

If you need display no record found message in codebehind

if(ds.Tables[0].Rows.Count==0)
{
ds.Tables[0].Rows.Add(ds.Tables[0].NewRow());
gvdata.DataSource = ds;
gvdata.DataBind();
int columncount = gvdata.Rows[0].Cells.Count;
gvdata.Rows[0].Cells.Clear();
gvdata.Rows[0].Cells.Add(new TableCell());
gvdata.Rows[0].Cells[0].ColumnSpan = columncount;
gvdata.Rows[0].Cells[0].Text = "No Records Found";
}

Asp.net show gridview header when there is no data or empty

1
  • Thanks sir! A very helpful answer for a very simple question. :D Feb 20, 2014 at 7:51
1

there is a property called ShowHeaderWhenEmpty ,set it as true

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