DetailsView.DefaultMode 属性

定义

获取或设置 DetailsView 控件的默认数据输入模式。

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

DetailsViewMode 值之一。 默认值为 DetailsViewMode.ReadOnly

例外

指定的值不是 DetailsViewMode 枚举值之一。

示例

下面的代码示例演示如何使用 DefaultMode 属性指定 DetailsView 控件应在更新记录后保持编辑模式。


<%@ 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>

注解

使用 DefaultMode 属性指定在执行编辑或插入操作后控件是否 DetailsView 返回编辑、插入或只读模式。 默认情况下,控件 DetailsView 返回只读模式;但是,通过将此属性设置为适当的值,可以将控件保持 DetailsView 编辑或插入模式。 下表列出了不同的模式值。

“模式” 说明
DetailsViewMode.Edit 控件 DetailsView 处于编辑模式,允许用户更新记录的值。
DetailsViewMode.Insert 控件 DetailsView 处于插入模式,允许用户向数据源添加新记录。
DetailsViewMode.ReadOnly 控件 DetailsView 处于只读模式,这是正常的显示模式。

适用于

另请参阅