DetailsView.Caption 属性

定义

获取或设置要在 DetailsView 控件的 HTML 标题元素中呈现的文本。Gets or sets the text to render in an HTML caption element in a DetailsView control. 提供此属性的目的是使辅助技术设备的用户更易于访问控件。This property is provided to make the control more accessible to users of assistive technology devices.

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

属性值

一个字符串,表示要在 DetailsView 控件的 HTML 标题元素中呈现的文本。A string that represents the text to render in an HTML caption element in a DetailsView control. 默认值为空字符串 ("")。The default value is an empty string ("").

示例

下面的代码示例演示如何使用Caption属性指定DetailsView控件中呈现的 HTML caption 元素的文本。The following code example demonstrates how to use the Caption property to specify the text for the HTML caption element rendered in a DetailsView control.


<%@ 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>DetailsView Caption and CaptionAlign Example</title>
</head>
<body>
    <form id="Form1" runat="server">
        
      <h3>DetailsView Caption and CaptionAlign Example</h3>
                
        <asp:detailsview id="CustomerDetailView"
          datasourceid="DetailsViewSource"
          datakeynames="CustomerID"
          autogeneraterows="true"
          allowpaging="true"
          caption="Customer Details"
          captionalign="Left"  
          runat="server">
               
          <headerstyle backcolor="Navy"
            forecolor="White"/>
                    
        </asp:detailsview>
        
        <!-- 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="DetailsViewSource" runat="server" 
          ConnectionString=
            "<%$ ConnectionStrings:NorthWindConnectionString%>"
          InsertCommand="INSERT INTO [Customers]([CustomerID], 
            [CompanyName], [Address], [City], [PostalCode], [Country]) 
            VALUES (@CustomerID, @CompanyName, @Address, @City, 
            @PostalCode, @Country)"
          SelectCommand="Select [CustomerID], [CompanyName], 
            [Address], [City], [PostalCode], [Country] 
            From [Customers]">
        </asp:SqlDataSource>
    </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>DetailsView Caption and CaptionAlign Example</title>
</head>
<body>
    <form id="Form1" runat="server">
        
      <h3>DetailsView Caption and CaptionAlign Example</h3>
                
        <asp:detailsview id="CustomerDetailView"
          datasourceid="DetailsViewSource"
          datakeynames="CustomerID"
          autogeneraterows="true"
          allowpaging="true"
          caption="Customer Details"
          captionalign="Left"  
          runat="server">
               
          <headerstyle backcolor="Navy"
            forecolor="White"/>
                    
        </asp:detailsview>
        
        <!-- 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="DetailsViewSource" runat="server" 
          ConnectionString=
            "<%$ ConnectionStrings:NorthWindConnectionString%>"
          InsertCommand="INSERT INTO [Customers]([CustomerID], 
            [CompanyName], [Address], [City], [PostalCode], [Country]) 
            VALUES (@CustomerID, @CompanyName, @Address, @City, 
            @PostalCode, @Country)"
          SelectCommand="Select [CustomerID], [CompanyName], 
            [Address], [City], [PostalCode], [Country] 
            From [Customers]">
        </asp:SqlDataSource>
    </form>
  </body>
</html>

注解

使用属性指定要在DetailsView控件中的 HTML 标题元素中呈现的文本。 CaptionUse the Caption property to specify the text to render in an HTML caption element in a DetailsView control. 指定的文本为辅助技术设备提供了可用于使控件更易于访问的表的说明。The text that you specify provides assistive technology devices with a description of the table that can be used to make the control more accessible.

DetailsView控件的其他辅助功能支持CaptionAlign由属性提供。Additional accessibility support for the DetailsView control is provided by the CaptionAlign property. 使用属性指定DetailsView控件中的 HTML 标题元素的对齐方式。 CaptionAlignUse the CaptionAlign property to specify the alignment of the HTML caption element in a DetailsView control.

的值Caption存储在视图状态中。The value of Caption is stored in view state.

设置此属性后, 可以使用设计器工具自动将此属性的值保存到资源文件中。The value of this property, when set, can be saved automatically to a resource file by using a designer tool. 有关详细信息, 请LocalizableAttribute参阅和全球化和本地化For more information, see LocalizableAttribute and Globalization and Localization.

适用于

另请参阅