Resource Page DescriptionA more elegant solution to display GridView header and footer when the data source is empty.
I think the need to always show the header and footer of a GridView is pretty common.
When I first ran into this problem, I went to Google and found lots of content about this.
Some suggest tampering with the data source to add an extra row if it’s empty. Others show overriding the CreateChildControls method.
I was not satisfied with either of these solutions. I didn’t like that dirty feeling I had by tampering with the data source. And I didn’t like overriding the CreateChildControls method because it simply didn’t work of me anyway. This solution only gave the appearance of the header and footer existing. I ran into issues because I was programmatically adding controls to the header. Upon postback, if the data source was empty, the control hierarchy would not be the same as before thus causing an error.
I blogged about this here
http://weblogs.asp.net/joewrobel/archive/2008/01/30/a-more-elegant-solution-to-display-gridview-header-and-footer-when-the-data-source-is-empty.aspx