Share via


DetailsViewModeEventArgs Kelas

Definisi

Menyediakan data untuk peristiwa tersebut ModeChanging .

public ref class DetailsViewModeEventArgs : System::ComponentModel::CancelEventArgs
public class DetailsViewModeEventArgs : System.ComponentModel.CancelEventArgs
type DetailsViewModeEventArgs = class
    inherit CancelEventArgs
Public Class DetailsViewModeEventArgs
Inherits CancelEventArgs
Warisan
DetailsViewModeEventArgs

Contoh

Contoh kode berikut menunjukkan cara menggunakan objek yang DetailsViewModeEventArgs diteruskan ke penanganan aktivitas agar ModeChanging peristiwa menyembunyikan baris pager saat DetailsView kontrol beralih ke 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 CustomerDetailsView_ModeChanging(Object sender, DetailsViewModeEventArgs e)
  {

    // Use the NewMode property to determine the mode to which the 
    // DetailsView control is transitioning.
    switch (e.NewMode)
    {
      case DetailsViewMode.Edit:
        // Hide the pager row and clear the Label control
        // when transitioning to edit mode.
        CustomerDetailsView.AllowPaging = false;
        MessageLabel.Text = "";
        break;
      case DetailsViewMode.ReadOnly:
        // Display the pager row and confirmation message
        // when transitioning to edit mode.
        CustomerDetailsView.AllowPaging = true;
        if (e.CancelingEdit)
        {
          MessageLabel.Text = "Update canceled.";
        }
        else
        {
          MessageLabel.Text = "Update completed.";
        }
        break;
      case DetailsViewMode.Insert:
        // Cancel the mode change if the DetailsView
        // control attempts to transition to insert 
        // mode.
        e.Cancel = true;
        break;
      default:
        MessageLabel.Text = "Unsupported mode.";
        break;
    }
    
  }

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>DetailsViewModeEventArgs Example</title>
</head>
<body>
    <form id="form1" runat="server">
        
      <h3>DetailsViewModeEventArgs Example</h3>
                
      <asp:detailsview id="CustomerDetailsView"
        datasourceid="DetailsViewSource"
        datakeynames="CustomerID"
        autogeneraterows="true"
        autogenerateeditbutton="true" 
        allowpaging="true"
        onmodechanging="CustomerDetailsView_ModeChanging" 
        runat="server">

      </asp:detailsview>
      
      <br/><br/>
      
      <asp:label id="MessageLabel"
        forecolor="Red"
        runat="server"/>
          
      <!-- 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"
        selectcommand="Select [CustomerID], [CompanyName], [Address], 
          [City], [PostalCode], [Country] From [Customers]"
        updatecommand="Update [Customers] Set 
          [CompanyName]=@CompanyName, [Address]=@Address, 
          [City]=@City, [PostalCode]=@PostalCode, 
          [Country]=@Country 
          Where [CustomerID]=@CustomerID" 
        connectionstring=
          "<%$ ConnectionStrings:NorthWindConnectionString%>" 
        runat="server"/>
            
    </form>
  </body>
</html>

<%@ Page language="VB" autoeventwireup="false" %>

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

  Sub CustomerDetailsView_ModeChanging(ByVal sender As Object, ByVal e As DetailsViewModeEventArgs) Handles CustomerDetailsView.ModeChanging

    ' Use the NewMode property to determine the mode to which the 
    ' DetailsView control is transitioning.
    Select Case e.NewMode
    
      Case DetailsViewMode.Edit
        ' Hide the pager row and clear the Label control
        ' when transitioning to edit mode.
        CustomerDetailsView.AllowPaging = False
        MessageLabel.Text = ""

      Case DetailsViewMode.ReadOnly
        ' Display the pager row and confirmation message
        ' when transitioning to edit mode.
        CustomerDetailsView.AllowPaging = True
        If e.CancelingEdit Then
        
          MessageLabel.Text = "Update canceled."
        
        Else
        
          MessageLabel.Text = "Update completed."
        
        End If

      Case DetailsViewMode.Insert
        ' Cancel the mode change if the DetailsView
        ' control attempts to transition to insert 
        ' mode.
        e.Cancel = True

      Case Else
        MessageLabel.Text = "Unsupported mode."
          
    End Select
    
  End Sub

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>DetailsViewModeEventArgs Example</title>
</head>
<body>
    <form id="form1" runat="server">
        
      <h3>DetailsViewModeEventArgs Example</h3>
                
      <asp:detailsview id="CustomerDetailsView"
        datasourceid="DetailsViewSource"
        datakeynames="CustomerID"
        autogeneraterows="true"
        autogenerateeditbutton="true" 
        allowpaging="true"
        runat="server">

      </asp:detailsview>
      
      <br/><br/>
      
      <asp:label id="MessageLabel"
        forecolor="Red"
        runat="server"/>
          
      <!-- 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"
        selectcommand="Select [CustomerID], [CompanyName], [Address], 
          [City], [PostalCode], [Country] From [Customers]"
        updatecommand="Update [Customers] Set 
          [CompanyName]=@CompanyName, [Address]=@Address, 
          [City]=@City, [PostalCode]=@PostalCode, 
          [Country]=@Country 
          Where [CustomerID]=@CustomerID" 
        connectionstring=
          "<%$ ConnectionStrings:NorthWindConnectionString%>" 
        runat="server"/>
            
    </form>
  </body>
</html>

Keterangan

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

Objek DetailsViewModeEventArgs diteruskan ke penanganan aktivitas, yang memungkinkan Anda menentukan mode DetailsView yang kontrolnya berubah, untuk menentukan apakah ModeChanging peristiwa dinaikkan sebagai akibat dari pengguna membatalkan operasi pengeditan, atau untuk menunjukkan bahwa operasi penyisipan harus dibatalkan. Untuk menentukan mode baru, gunakan NewMode properti . Anda juga dapat menggunakan NewMode properti untuk mengubah ke mode alternatif dengan mengaturnya ke salah DetailsViewMode satu nilai enumerasi. CancelingEdit Gunakan properti untuk menentukan apakah pengguna membatalkan operasi edit. Untuk membatalkan operasi penyisipan, atur properti ke Canceltrue.

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

Untuk daftar nilai properti awal untuk instans DetailsViewModeEventArgs kelas , lihat DetailsViewModeEventArgs konstruktor .

Konstruktor

DetailsViewModeEventArgs(DetailsViewMode, Boolean)

Menginisialisasi instans baru kelas DetailsViewModeEventArgs.

Properti

Cancel

Mendapatkan atau menetapkan nilai yang menunjukkan apakah acara harus dibatalkan.

(Diperoleh dari CancelEventArgs)
CancelingEdit

Mendapatkan nilai yang menunjukkan apakah ModeChanging peristiwa dinaikkan sebagai akibat dari pengguna membatalkan operasi pengeditan.

NewMode

Mendapatkan atau mengatur mode yang DetailsView akan diubah oleh kontrol.

Metode

Equals(Object)

Menentukan apakah objek yang ditentukan sama dengan objek saat ini.

(Diperoleh dari Object)
GetHashCode()

Berfungsi sebagai fungsi hash default.

(Diperoleh dari Object)
GetType()

Mendapatkan dari instans Type saat ini.

(Diperoleh dari Object)
MemberwiseClone()

Membuat salinan dangkal dari saat ini Object.

(Diperoleh dari Object)
ToString()

Mengembalikan string yang mewakili objek saat ini.

(Diperoleh dari Object)

Berlaku untuk

Lihat juga