다음을 통해 공유


DetailsView.ModeChanged 이벤트

정의

DetailsView 컨트롤 모드를 편집, 삽입 및 읽기 전용 모드 사이에서 변경하려 하면 CurrentMode 속성이 업데이트된 후에 이 이벤트가 발생합니다.

public:
 event EventHandler ^ ModeChanged;
public event EventHandler ModeChanged;
member this.ModeChanged : EventHandler 
Public Custom Event ModeChanged As EventHandler 

이벤트 유형

예제

다음 코드 예제를 사용 ModeChanged 하는 방법에 설명 합니다 헤더 행에 현재 모드를 표시 하는 이벤트입니다.


<%@ Page language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">

    void CustomerDetailView_ModeChanged(Object sender, EventArgs e)
  {
    // Display the current mode in the header row.
      switch (CustomerDetailView.CurrentMode)
    {
      case DetailsViewMode.Edit:
        CustomerDetailView.HeaderText = "Edit Mode";
        CustomerDetailView.HeaderStyle.ForeColor = System.Drawing.Color.Red;
        CustomerDetailView.HeaderStyle.BackColor = System.Drawing.Color.LightGray;
        break;
      case DetailsViewMode.Insert:
        CustomerDetailView.HeaderText = "Insert Mode";
        CustomerDetailView.HeaderStyle.ForeColor = System.Drawing.Color.Green;
        CustomerDetailView.HeaderStyle.BackColor = System.Drawing.Color.Yellow;
        break;
      case DetailsViewMode.ReadOnly:
        CustomerDetailView.HeaderText = "Read-Only Mode";
        CustomerDetailView.HeaderStyle.ForeColor = System.Drawing.Color.Blue;
        CustomerDetailView.HeaderStyle.BackColor = System.Drawing.Color.White;
        break;
      default:
          CustomerDetailView.HeaderText = "Error!";
        break;
    }
  }

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>DetailsView ModeChanged Example</title>
</head>
<body>
    <form id="Form1" runat="server">
        
      <h3>DetailsView ModeChanged Example</h3>      
                
        <asp:detailsview id="CustomerDetailView"
          datasourceid="DetailsViewSource"
          datakeynames="CustomerID"
          autogeneraterows="true"
          autogenerateeditbutton="true"
          autogenerateinsertbutton="true"  
          allowpaging="true"
          headertext="Read-Only Mode" 
          onmodechanged="CustomerDetailView_ModeChanged" 
          runat="server">
               
          <fieldheaderstyle backcolor="Navy"
            forecolor="White"/>
            
          <headerstyle forecolor="Blue"/>
                    
        </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">
<script runat="server">

    Sub CustomerDetailView_ModeChanged(ByVal sender As Object, ByVal e As EventArgs)
  
        ' Display the current mode in the header row.
        Select Case CustomerDetailView.CurrentMode

            Case DetailsViewMode.Edit
                CustomerDetailView.HeaderText = "Edit Mode"
                CustomerDetailView.HeaderStyle.ForeColor = System.Drawing.Color.Red
                CustomerDetailView.HeaderStyle.BackColor = System.Drawing.Color.LightGray

            Case DetailsViewMode.Insert
                CustomerDetailView.HeaderText = "Insert Mode"
                CustomerDetailView.HeaderStyle.ForeColor = System.Drawing.Color.Green
                CustomerDetailView.HeaderStyle.BackColor = System.Drawing.Color.Yellow

            Case DetailsViewMode.ReadOnly
                CustomerDetailView.HeaderText = "Read-Only Mode"
                CustomerDetailView.HeaderStyle.ForeColor = System.Drawing.Color.Blue
                CustomerDetailView.HeaderStyle.BackColor = System.Drawing.Color.White

            Case Else
                CustomerDetailView.HeaderText = "Error!"
        
        End Select
    
    End Sub
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>DetailsView ModeChanged Example</title>
</head>
<body>
    <form id="Form1" runat="server">
        
      <h3>DetailsView ModeChanged Example</h3>      
                
        <asp:detailsview id="CustomerDetailView"
          datasourceid="DetailsViewSource"
          datakeynames="CustomerID"
          autogeneraterows="true"
          autogenerateeditbutton="true"
          autogenerateinsertbutton="true"  
          allowpaging="true"
          headertext="Read-Only Mode" 
          onmodechanged="CustomerDetailView_ModeChanged" 
          runat="server">
               
          <fieldheaderstyle backcolor="Navy"
            forecolor="White"/>
            
          <headerstyle forecolor="Blue"/>
                    
        </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>

설명

ModeChanged 이벤트는 컨트롤이 편집, 삽입 및 읽기 전용 모드 간에 변경하려고 하지만 속성이 CurrentMode 업데이트된 후에 발생 DetailsView 합니다. 이렇게 하면 이 이벤트가 발생할 때마다 컨트롤을 다른 컨트롤과 동기화하는 등 사용자 지정 루틴을 DetailsView 수행하는 이벤트 처리기를 제공할 수 있습니다.

이벤트를 처리 하는 방법에 대 한 자세한 내용은 참조 하세요. 이벤트 처리 및 발생합니다.

적용 대상

추가 정보