DetailsView.DefaultMode 属性

定义

获取或设置 DetailsView 控件的默认数据输入模式。Get or sets the default data-entry mode of the DetailsView control.

public:
 virtual property System::Web::UI::WebControls::DetailsViewMode DefaultMode { System::Web::UI::WebControls::DetailsViewMode get(); void set(System::Web::UI::WebControls::DetailsViewMode value); };
public virtual System.Web.UI.WebControls.DetailsViewMode DefaultMode { get; set; }
member this.DefaultMode : System.Web.UI.WebControls.DetailsViewMode with get, set
Public Overridable Property DefaultMode As DetailsViewMode

属性值

DetailsViewMode 值之一。One of the DetailsViewMode values. 默认值为 DetailsViewMode.ReadOnlyThe default is DetailsViewMode.ReadOnly.

异常

指定的值不是 DetailsViewMode 枚举值之一。The specified value is not one of the DetailsViewMode enumeration values.

示例

下面的代码示例演示如何使用DefaultMode属性来指定DetailsView在更新记录后控件应保持在编辑模式下。The following code example demonstrates how to use the DefaultMode property to specify that the DetailsView control should remain in edit mode after a record has been updated.


<%@ 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 DefaultMode Example</title>
</head>
<body>
    <form id="Form1" runat="server">
        
      <h3>DetailsView DefaultMode Example</h3>
                
        <asp:detailsview id="CustomerDetailView"
          datasourceid="DetailsViewSource"
          datakeynames="CustomerID"
          autogenerateeditbutton="true"   
          autogeneraterows="true"
          allowpaging="true"
          defaultmode="Edit"   
          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 DefaultMode Example</title>
</head>
<body>
    <form id="Form1" runat="server">
        
      <h3>DetailsView DefaultMode Example</h3>
                
        <asp:detailsview id="CustomerDetailView"
          datasourceid="DetailsViewSource"
          datakeynames="CustomerID"
          autogenerateeditbutton="true"   
          autogeneraterows="true"
          allowpaging="true"
          defaultmode="Edit"   
          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或插入操作后控件是返回到编辑、插入还是只读模式。 DefaultModeUse the DefaultMode property to specify whether the DetailsView control returns to edit, insert, or read-only mode after an edit or insert operation is performed. 默认情况下, DetailsView控件将返回到只读模式; 但是, 您可以通过将此DetailsView属性设置为适当的值, 使控件处于 "编辑" 或 "插入" 模式。By default, the DetailsView control returns to read-only mode; however, you can keep the DetailsView control in edit or insert mode by setting this property to the appropriate value. 下表列出了不同的模式值。The following table lists the different mode values.

模式Mode 说明Description
DetailsViewMode.Edit DetailsView控件处于编辑模式, 这允许用户更新记录的值。The DetailsView control is in edit mode, which allows the user to update the values of a record.
DetailsViewMode.Insert DetailsView控件处于插入模式, 这允许用户向数据源添加新记录。The DetailsView control is in insert mode, which allows the user to add a new record to the data source.
DetailsViewMode.ReadOnly DetailsView控件处于只读模式, 这是正常的显示模式。The DetailsView control is in read-only mode, which is the normal display mode.

适用于

另请参阅