Geeks With Blogs

Tiago Salgado .NET / SQL Server / IT / etc...

Since .NET Framework 3.5, to show the Header row in empty GridView, you need to do some trick like:


List<string> rows = new List<string>(
    new string[] { "line1", "line2", "line3" });

if (rows.Count > 0)
    gv.DataSource = rows;
    gv.DataSource = rows;
    gv.Rows[0].Visible = false;

Obvious, the “else” condition will be always executed, but this is only for exemplify.

On .NET Framework 4.0, was introduced a new property, who makes the Header always visible without any trick. That property is ShowHeaderWhenEmpty.

<asp:GridView runat="server" ID="gv" ShowHeaderWhenEmpty="true">
Posted on Saturday, March 26, 2011 4:29 PM | Back to top

Comments on this post: GridView ShowHeaderWhenEmpty

# re: GridView ShowHeaderWhenEmpty
Requesting Gravatar...
Hi, in .Net Framework exists other way to show headers when data is empty,

<asp:GridView runat="server" ID="gv" >
-- Put the columns here, simulating headers
Left by Eduardo Miranda on Feb 24, 2015 1:33 PM

Your comment:
 (will show your gravatar)

Copyright © Tiago Salgado | Powered by: