Bagikan melalui


DetailsView.ModeChanging Kejadian

Definisi

Terjadi ketika DetailsView kontrol mencoba mengubah antara mode edit, sisipkan, dan baca-saja, tetapi sebelum properti diperbarui CurrentMode .

public:
 event System::Web::UI::WebControls::DetailsViewModeEventHandler ^ ModeChanging;
public event System.Web.UI.WebControls.DetailsViewModeEventHandler ModeChanging;
member this.ModeChanging : System.Web.UI.WebControls.DetailsViewModeEventHandler 
Public Custom Event ModeChanging As DetailsViewModeEventHandler 

Jenis Acara

Contoh

Contoh kode berikut menunjukkan cara menggunakan ModeChanging peristiwa untuk menonaktifkan fitur paging saat DetailsView kontrol dalam mode edit.


<%@ 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_ModeChanging(Object sender, DetailsViewModeEventArgs e)
  {
    // Disable the paging feature in edit mode.
    if (e.NewMode == DetailsViewMode.Edit)
    {
        CustomerDetailView.AllowPaging = false;
    }
    else
    {
        CustomerDetailView.AllowPaging = true;
    }
  }

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>DetailsView ModeChanging Example</title>
</head>
<body>
    <form id="Form1" runat="server">
        
      <h3>DetailsView ModeChanging Example</h3>
                
        <asp:detailsview id="CustomerDetailView"
          datasourceid="DetailsViewSource"
          datakeynames="CustomerID"
          autogeneraterows="true"
          autogenerateeditbutton="true" 
          allowpaging="true"
          onmodechanging="CustomerDetailView_ModeChanging" 
          runat="server">
               
          <fieldheaderstyle 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">
<script runat="server">

    Sub CustomerDetailView_ModeChanging(ByVal sender As Object, ByVal e As DetailsViewModeEventArgs)
        ' Disable the paging feature in edit mode.
        If e.NewMode = DetailsViewMode.Edit Then
            CustomerDetailView.AllowPaging = False
        Else
            CustomerDetailView.AllowPaging = True
        End If
    End Sub

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>DetailsView ModeChanging Example</title>
</head>
<body>
    <form id="Form1" runat="server">
        
      <h3>DetailsView ModeChanging Example</h3>
                
        <asp:detailsview id="CustomerDetailView"
          datasourceid="DetailsViewSource"
          datakeynames="CustomerID"
          autogeneraterows="true"
          autogenerateeditbutton="true" 
          allowpaging="true"
          onmodechanging="CustomerDetailView_ModeChanging" 
          runat="server">
               
          <fieldheaderstyle 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>

Keterangan

Peristiwa ModeChanging dimunculkan ketika DetailsView kontrol mencoba mengubah antara mode edit, sisipkan, dan baca-saja, tetapi sebelum properti diperbarui CurrentMode . Ini memungkinkan Anda untuk menyediakan penanganan aktivitas yang melakukan rutinitas kustom, seperti membatalkan perubahan mode, setiap kali peristiwa ini terjadi.

Objek DetailsViewModeEventArgs diteruskan ke penanganan aktivitas, yang memungkinkan Anda menentukan mode baru, untuk menentukan apakah perubahan mode adalah hasil dari pengguna yang membatalkan operasi edit, atau membatalkan perubahan mode. Untuk menentukan mode baru, gunakan NewMode properti . Untuk menentukan apakah perubahan mode adalah hasil dari pengguna yang membatalkan operasi edit, gunakan CancelingEdit properti . Anda dapat membatalkan perubahan mode dengan mengatur properti ke Canceltrue.

Untuk informasi selengkapnya tentang cara menangani peristiwa, lihat Menangani dan Menaikkan Peristiwa.

Berlaku untuk

Lihat juga