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 - 事件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.

適用於

另請參閱