GridView.Caption 属性

定义

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

public virtual string Caption { get; set; }

属性值

一个字符串,表示要在 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>

注解

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

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

适用于

产品 版本
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1

另请参阅