DetailsViewMode 列舉

定義

表示 DetailsView 控制項的不同資料輸入模式。

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

欄位

Edit 1

編輯模式,允許使用者更新現有資料錄的值。

Insert 2

插入模式,允許使用者輸入新資料錄的值。

ReadOnly 0

顯示模式,防止使用者修改資料錄的值。

範例

下列程式碼範例示範如何將 屬性設定 DefaultModeDetailsViewMode.Edit ,讓控制項在更新作業之後保持 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>

備註

列舉 DetailsViewMode 可用來表示 控制項的資料輸入模式 DetailsView 。 若要判斷控制項的目前模式,請使用 CurrentMode 屬性。 插入或更新作業之後, DetailsView 控制項會返回 屬性所 DefaultMode 指定的模式。 根據預設,控制項會返回唯讀模式。 您可以藉由設定 屬性來指定要傳回的 DefaultMode 替代模式。 若要以程式設計方式變更模式,請使用 ChangeMode 方法。 DetailsView當控制項變更模式時,會引發下表中的事件。

Event - 事件 描述
ModeChanging 發生于 DetailsView 控制項嘗試在編輯、插入和唯讀模式之間變更,但在模式實際變更之前。 此事件通常用於取消模式變更。
ModeChanged 發生于控制項從編輯、插入或唯讀模式變更為另一個模式之後 DetailsView 。 當控制項變更模式時 DetailsView ,通常會使用此事件來執行工作。

適用於

另請參閱