GridView.Caption 属性

定义

获取或设置要在 GridView 控件的 HTML 标题元素中呈现的文本。 提供此属性的目的是使辅助技术设备的用户更易于访问控件。

public:
 virtual property System::String ^ Caption { System::String ^ get(); void set(System::String ^ value); };
public virtual string Caption { get; set; }
member this.Caption : string with get, set
Public Overridable Property Caption As String

属性值

String

一个字符串,表示要在 GridView 控件的 HTML 标题元素中呈现的文本。 默认值为空字符串 ("")。

示例

下面的示例演示如何使用 Caption 属性指定控件的 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 Caption and CaptionAlign Example</title>
</head>
<body>
    <form id="form1" runat="server">
        
      <h3>GridView Caption and CaptionAlign Example</h3>

      <asp:gridview id="CustomersGridView" 
        datasourceid="CustomersSource" 
        autogeneratecolumns="true"
        emptydatatext="No data available." 
        allowpaging="true"
        caption="Customer Information Table"
        captionalign="Top"   
        runat="server">                
      </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 Caption and CaptionAlign Example</title>
</head>
<body>
    <form id="form1" runat="server">
        
      <h3>GridView Caption and CaptionAlign Example</h3>

      <asp:gridview id="CustomersGridView" 
        datasourceid="CustomersSource" 
        autogeneratecolumns="true"
        emptydatatext="No data available." 
        allowpaging="true"
        caption="Customer Information Table"
        captionalign="Top"   
        runat="server">                
      </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>

注解

使用 Caption 属性指定要在控件中的 HTML 标题元素中 GridView 呈现的文本。 你指定的文本提供辅助技术设备,其中包含可用于使控件更易于访问的表的说明。 还可以使用 CaptionAlign 属性指定用于呈现 HTML 标题元素的位置。

设置时,此属性的值可以使用设计器工具自动保存到资源文件中。 有关详细信息,请参阅LocalizableAttribute全球化和本地化

适用于

另请参阅