I realized that ShowHeaderWhenEmpty only works in PostBacks. Is there any way to make it work once the page is loaded?
<asp:GridView ID="GridView1"... ShowHeaderWhenEmpty="true"... >
<EmptyDataTemplate>
<asp:Label ID="Label1" runat="server" Text="No records found"></asp:Label>
</EmptyDataTemplate>
When I have no info to show, the above message only appears in PostBacks, no when the page is loaded.
Note: This answer assumes (based on your question) you are binding your
GridViewto a data source on PostBack, and not at all duringPage_Load. Please correct me if I’m wrong.The
<EmptyDataTemplate>content only shows once yourGridViewhas been databound. If you are only databinding on Postback (based on some user interaction) one way to solve this problem would be to bind yourGridViewto an empty (artificial) dataset, just so the<EmptyDataTemplate>will show.From the MSDN article on the EmptyDataTemplate (emphasis mine):
If there is no datasource bound to the control, this property is not yet relevant.