GridView控件 - 空了数据源显示标题 [英] GridView - Show headers on empty data source
问题描述
在C#中我如何仍然显示的GridView的头,甚至与数据源为空。
In C# how do I still show the headers of a gridview, even with the data source is empty.
我不是自动生成的列,因为它们都pdefined $ P $。
I am not auto generating the columns as they are all predefined.
目前我在做什么如下。
获取一个DataTable从存储过程回来,然后设置GridView控件的数据源,然后调用DataBind()。
Get a DataTable back from a stored procedure, then set the DataSource of the gridview, and then call DataBind().
这工作得很好,当我有数据,但没有返回行,那么我只是得到了一个空白点,其中电网应该的。
This works fine when I have data, but when no rows are returned then I just get a blank spot where the grid should be.
推荐答案
ASP.Net 4.0添加了布尔 ShowHeaderWhenEmpty
属性。
ASP.Net 4.0 added the boolean ShowHeaderWhenEmpty
property.
<一个href=\"http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.showheaderwhenempty.aspx\">http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.showheaderwhenempty.aspx
<asp:GridView runat="server" ID="GridView1" ShowHeaderWhenEmpty="true" AutoGenerateColumns="false">
<Columns>
<asp:BoundField HeaderText="First Name" DataField="FirstName" />
<asp:BoundField HeaderText="Last Name" DataField="LastName" />
</Columns>
</asp:GridView>
注:标题不会出现,除非的DataBind()被调用,NULL以外的东西。
Note: the headers will not appear unless DataBind() is called with something other than null.
GridView1.DataSource = New List(Of String)
GridView1.DataBind()
这篇关于GridView控件 - 空了数据源显示标题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!