DetailsView.AutoGenerateRows 属性

定义

获取或设置一个值,该值指示对应于数据源中每个字段的行字段是否自动生成并在 DetailsView 控件中显示。Gets or sets a value indicating whether row fields for each field in the data source are automatically generated and displayed in a DetailsView control.

public:
 virtual property bool AutoGenerateRows { bool get(); void set(bool value); };
public virtual bool AutoGenerateRows { get; set; }
member this.AutoGenerateRows : bool with get, set
Public Overridable Property AutoGenerateRows As Boolean

属性值

true 表示显示对应于数据源中每个字段的自动生成的绑定行字段;否则为 falsetrue to display automatically generated bound row fields for each field in the data source; otherwise, false. 默认值为 trueThe default is true.

示例

下面的代码示例演示如何使用AutoGenerateRows属性为数据源中的每个字段自动创建绑定行字段。The following code example demonstrates how to use the AutoGenerateRows property to automatically create bound row fields for each field in the data source.


<%@ 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 AutoGenerateRows Example</title>
</head>
<body>
    <form id="Form1" runat="server">
        
      <h3>DetailsView AutoGenerateRows Example</h3>
                
        <asp:detailsview id="CustomerDetailView"
          datasourceid="DetailsViewSource"
          datakeynames="CustomerID"
          autogeneraterows="true"
          allowpaging="true"  
          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 AutoGenerateRows Example</title>
</head>
<body>
    <form id="Form1" runat="server">
        
      <h3>DetailsView AutoGenerateRows Example</h3>
                
        <asp:detailsview id="CustomerDetailView"
          datasourceid="DetailsViewSource"
          datakeynames="CustomerID"
          autogeneraterows="true"
          allowpaging="true"  
          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控件中的每个数据行都用行字段表示。Each data row in the DetailsView control is represented by a row field. 当属性设置为true时, 将为数据源中的每个字段创建自动生成的绑定行字段。 AutoGenerateRowsWhen the AutoGenerateRows property is set to true, an automatically generated bound row field is created for each field in the data source. 然后, 每个字段在行中显示为文本, 并按照每个字段在数据源中的显示顺序显示。Each field is then displayed in a row as text, in the order in which each field appears in the data source.

备注

自动生成的Fields绑定行字段不会添加到集合中。Automatically generated bound row fields are not added to the Fields collection.

自动生成行可提供一种快速简单的方法来显示记录中的每个字段。Automatically generating the rows provides a quick and easy way to display every field in the record. 但是, 若要使用DetailsView控件的高级功能, 必须显式声明要包含DetailsView在控件中的行字段。However, to make use of the DetailsView control's advanced capabilities you must explicitly declare the row fields to include in the DetailsView control. 有关详细信息,请参阅 FieldsFor more information, see Fields.

备注

显式声明的行字段可与自动生成的行字段结合使用。Explicitly declared row fields can be used in combination with automatically generated row fields. 如果同时使用这两种方法, 将首先呈现显式声明的行字段, 然后呈现自动生成的行字段。When both are used, explicitly declared row fields are rendered first, followed by the automatically generated row fields.

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

适用于

另请参阅