I am using a Gridview with datasource is a List. How can I show the header if the List is null or for a empty gridview?
A:
You can use HeaderTemplate property to setup the head programatically or use ListView instead if you are using .NET 3.5.
or
You can even try below
//if data exists
if (dtSource.Rows.Count != 0)
{
grdView.DataSource = dtSource;
grdView.DataBind();
}
else
{
//Other wise add a emtpy "New Row" to the datatable and then hide it after binding.
dtFunding.Rows.Add(dtSource.NewRow());
grdView.DataSource = dtSource;
grdView.DataBind();
grdView.Rows[0].Visible = false;
}
Ravia
2010-01-11 05:41:31
I am not using datatable
Sauron
2010-01-11 06:09:43
A:
Please see the link below
http://asimsajjad.blogspot.com/2009/04/empty-data-template-of-gridview-control.html
Hope that will help.
Asim Sajjad
2010-01-22 06:26:52
A:
Dears i was writing in my blog about this issue but for c# , you can review the post and check if it will be helpful or not ,
http://blog.waleedmohamed.net/2009/04/show-grid-view-header-and-footer-when.html
i was using a generic way with an helper to retrieve an empty list to fill the gird please check and if u have any quest don't hesitate to contact me or ask it on stack site
Waleed Mohamed
2010-02-02 15:47:41