GridView.ShowHeader 属性
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
获取或设置一个值,该值指示是否在 GridView 控件中显示标题行。
public:
virtual property bool ShowHeader { bool get(); void set(bool value); };
public virtual bool ShowHeader { get; set; }
member this.ShowHeader : bool with get, set
Public Overridable Property ShowHeader As Boolean
属性值
若要显示标题行,则为 true
;否则为 false
。 默认值为 true
。
示例
以下示例演示如何使用 ShowHeader 属性在控件中 GridView 显示标题行。
<%@ Page language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>GridView ShowHeader and ShowFooter Example</title>
</head>
<body>
<form id="form1" runat="server">
<h3>GridView ShowHeader and ShowFooter Example</h3>
<asp:gridview id="CustomersGridView"
datasourceid="CustomersSource"
autogeneratecolumns="true"
emptydatatext="No data available."
showheader="true"
showfooter="true"
runat="server">
<headerstyle backcolor="LightCyan"
forecolor="MediumBlue"/>
<footerstyle backcolor="LightCyan"
forecolor="MediumBlue"/>
</asp:gridview>
<!-- This example uses Microsoft SQL Server and connects -->
<!-- to the Northwind sample database. Use an ASP.NET -->
<!-- expression to retrieve the connection string value -->
<!-- from the Web.config file. -->
<asp:sqldatasource id="CustomersSource"
selectcommand="Select [CustomerID], [CompanyName], [Address], [City], [PostalCode], [Country] From [Customers]"
connectionstring="<%$ ConnectionStrings:NorthWindConnectionString%>"
runat="server"/>
</form>
</body>
</html>
<%@ Page language="VB" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>GridView ShowHeader and ShowFooter Example</title>
</head>
<body>
<form id="form1" runat="server">
<h3>GridView ShowHeader and ShowFooter Example</h3>
<asp:gridview id="CustomersGridView"
datasourceid="CustomersSource"
autogeneratecolumns="true"
emptydatatext="No data available."
showheader="true"
showfooter="true"
runat="server">
<headerstyle backcolor="LightCyan"
forecolor="MediumBlue"/>
<footerstyle backcolor="LightCyan"
forecolor="MediumBlue"/>
</asp:gridview>
<!-- This example uses Microsoft SQL Server and connects -->
<!-- to the Northwind sample database. Use an ASP.NET -->
<!-- expression to retrieve the connection string value -->
<!-- from the Web.config file. -->
<asp:sqldatasource id="CustomersSource"
selectcommand="Select [CustomerID], [CompanyName], [Address], [City], [PostalCode], [Country] From [Customers]"
connectionstring="<%$ ConnectionStrings:NorthWindConnectionString%>"
runat="server"/>
</form>
</body>
</html>
注解
使用属性 ShowHeader 指定控件是否 GridView 显示标题行。 若要控制标题行的外观,请使用 HeaderStyle 该属性。