DetailsViewModeEventArgs Klasa

Definicja

Udostępnia dane dla zdarzenia ModeChanging.

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

Przykłady

W poniższym przykładzie kodu pokazano, jak użyć obiektu przekazanego DetailsViewModeEventArgs do programu obsługi zdarzeń dla ModeChanging zdarzenia, aby ukryć wiersz pagera, gdy DetailsView kontrolka przejdzie do trybu edycji.


<%@ 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>

Uwagi

Zdarzenie jest wywoływane, gdy DetailsView kontrolka ModeChanging próbuje zmienić tryb edycji, wstawiania i tylko do odczytu, ale przed faktycznie zmienia się tryb. Dzięki temu można udostępnić procedurę obsługi zdarzeń, która wykonuje niestandardową procedurę, taką jak konfigurowanie DetailsView kontrolki dla określonego trybu lub anulowanie zmiany trybu przy każdym wystąpieniu tego zdarzenia.

DetailsViewModeEventArgs Obiekt jest przekazywany do procedury obsługi zdarzeń, która umożliwia określenie trybu, w którym DetailsView zmienia się kontrolka, w celu określenia, czy ModeChanging zdarzenie zostało zgłoszone w wyniku anulowania operacji edycji przez użytkownika, czy wskazać, że operacja wstawiania powinna zostać anulowana. Aby określić nowy tryb, użyj NewMode właściwości . Możesz również użyć NewMode właściwości , aby zmienić tryb na alternatywny, ustawiając ją na jedną z DetailsViewMode wartości wyliczenia. CancelingEdit Użyj właściwości , aby określić, czy użytkownik anulował operację edycji. Aby anulować operację wstawiania, ustaw Cancel właściwość na true.

Aby uzyskać więcej informacji na temat obsługi zdarzeń, zobacz Obsługa i podnoszenie zdarzeń.

Aby uzyskać listę początkowych wartości właściwości dla wystąpienia DetailsViewModeEventArgs klasy, zobacz DetailsViewModeEventArgs konstruktor.

Konstruktory

DetailsViewModeEventArgs(DetailsViewMode, Boolean)

Inicjuje nowe wystąpienie klasy DetailsViewModeEventArgs.

Właściwości

Cancel

Pobiera lub ustawia wartość wskazującą, czy zdarzenie powinno zostać anulowane.

(Odziedziczone po CancelEventArgs)
CancelingEdit

Pobiera wartość wskazującą, czy ModeChanging zdarzenie zostało zgłoszone w wyniku anulowania operacji edycji przez użytkownika.

NewMode

Pobiera lub ustawia tryb, w którym zmienia się kontrolka DetailsView .

Metody

Equals(Object)

Określa, czy dany obiekt jest taki sam, jak bieżący obiekt.

(Odziedziczone po Object)
GetHashCode()

Służy jako domyślna funkcja skrótu.

(Odziedziczone po Object)
GetType()

Type Pobiera wartość bieżącego wystąpienia.

(Odziedziczone po Object)
MemberwiseClone()

Tworzy płytkią kopię bieżącego Objectelementu .

(Odziedziczone po Object)
ToString()

Zwraca ciąg reprezentujący bieżący obiekt.

(Odziedziczone po Object)

Dotyczy

Zobacz też