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 控件更改模式时,将引发下表中的事件。

事件 描述
ModeChanging DetailsView 控件尝试在编辑、插入和只读模式之间更改,但在模式实际更改之前发生。 此事件通常用于取消模式更改。
ModeChanged 在控件从编辑、插入或只读模式更改为另一种模式之后 DetailsView 发生。 此事件通常用于在控件更改模式时 DetailsView 执行任务。

适用于

另请参阅