DetailsViewMode 枚举

定义

表示 DetailsView 控件的各种数据输入模式。Represents the different data-entry modes of a DetailsView control.

public enum class DetailsViewMode
public enum DetailsViewMode
type DetailsViewMode = 
Public Enum DetailsViewMode
继承
DetailsViewMode

字段

Edit 1

编辑模式,允许用户更新现有记录的值。An editing mode that allows the user to update the values of an existing record.

Insert 2

插入模式,允许用户输入新记录的值。An inserting mode that allows the user to enter the values for a new record.

ReadOnly 0

显示模式,用户无法修改记录值。A display mode that prevents the user from modifying the values of a record.

示例

下面的代码示例演示了如何通过DetailsView DefaultMode将属性设置为DetailsViewMode.Edit, 使控件处于编辑模式。The following code example demonstrates how to keep the DetailsView control in edit mode after an update operation by setting the DefaultMode property to DetailsViewMode.Edit.


<%@ 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控件的数据输入模式。 DetailsViewModeThe DetailsViewMode enumeration is used to represent the data-entry modes of a DetailsView control. 若要确定控件的当前模式, 请使用CurrentMode属性。To determine the current mode of the control, use the CurrentMode property. 在插入或更新操作完成后, DetailsView控件将返回到DefaultMode属性指定的模式。After an insert or update operation, the DetailsView control returns to the mode specified by the DefaultMode property. 默认情况下, 该控件返回到只读模式。By default, the control returns to read-only mode. 可以通过设置DefaultMode属性来指定要返回到的备用模式。You can specify an alternate mode to return to by setting the DefaultMode property. 若要以编程方式更改模式ChangeMode , 请使用方法。To change modes programmatically, use the ChangeMode method. DetailsView当控件更改模式时, 将引发下表中的事件。When the DetailsView control changes modes, the events in the following table are raised.

事件Event 说明Description
ModeChanging DetailsView控件尝试在编辑、插入和只读模式之间更改时, 但在模式实际更改之前发生。Occurs when a DetailsView control attempts to change between edit, insert, and read-only mode, but before the mode actually changes. 此事件通常用于取消模式更改。This event is often used to cancel a mode change.
ModeChanged DetailsView控件从编辑、插入或只读模式更改为另一种模式之后发生。Occurs after a DetailsView control has changed from edit, insert, or read-only mode to another mode. 此事件通常用于在DetailsView控件更改模式时执行任务。This event is often used to perform a task when the DetailsView control changes modes.

适用于

另请参阅