Show empty GridView as empty grid

S

Steven Cheng[MSFT]

Hello Dave,

If you want to display Row (no matter empty or not), we have to bind
Gridview with a datasource. Actually, if the expected datasource's schema
is not very complex, you can simply create a empty DataTable and bind it to
GridView. e.g:


==========================
protected void Page_Load(object sender, EventArgs e)
{
DataTable dt = new DataTable();
dt.Columns.Add("name");
dt.Columns.Add("description");

dt.Rows.Add(new object[] {"","" });

GridView2.DataSource = dt;
GridView2.DataBind();
}
===========================

Otherwise, we can only use the EmptyDataTemplate to provide the UI to
display when there is no data.

===============
<EmptyDataTemplate>
..............
</EmptyDataTemplate>
</asp:GridView>
===============


Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


This posting is provided "AS IS" with no warranties, and confers no rights.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top