DetailsViewModeEventArgs Clase

Definición

Proporciona datos para el evento ModeChanging.Provides data for the ModeChanging event.

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

Ejemplos

En el ejemplo de código siguiente se muestra cómo DetailsViewModeEventArgs utilizar el objeto pasado al controlador de eventos ModeChanging para que el evento oculte la fila de paginación cuando el control realiza la DetailsView transición al modo de edición.The following code example demonstrates how to use the DetailsViewModeEventArgs object passed to the event handler for the ModeChanging event to hide the pager row when the DetailsView control transitions to edit mode.


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

Comentarios

El ModeChanging evento se desencadena cuando un DetailsView control intenta cambiar entre los modos de edición, inserción y solo lectura, pero antes de que el modo cambie realmente.The ModeChanging event is raised when a DetailsView control attempts to change between edit, insert, and read-only mode, but before the mode actually changes. Esto le permite proporcionar un controlador de eventos que realiza una rutina personalizada, como configurar el DetailsView control para un modo específico o cancelar el cambio de modo, cada vez que se produce este evento.This allows you to provide an event handler that performs a custom routine, such as configuring the DetailsView control for a specific mode or canceling the mode change, whenever this event occurs.

Un DetailsViewModeEventArgs objeto se pasa al controlador de eventos, que permite determinar el modo en el que el DetailsView control está cambiando, para determinar si se generó ModeChanging el evento como resultado de la cancelación de una operación de edición, o para indicar que se debe cancelar una operación de inserción.A DetailsViewModeEventArgs object is passed to the event handler, which allows you to determine the mode to which the DetailsView control is changing, to determine whether the ModeChanging event was raised as a result of the user canceling an edit operation, or to indicate that an insert operation should be canceled. Para determinar el nuevo modo, utilice la NewMode propiedad.To determine the new mode, use the NewMode property. También puede usar la NewMode propiedad para cambiar a un modo alternativo estableciéndolo en uno de los DetailsViewMode valores de enumeración.You can also use the NewMode property to change to an alternate mode by setting it to one of the DetailsViewMode enumeration values. Use la CancelingEdit propiedad para determinar si el usuario canceló una operación de edición.Use the CancelingEdit property to determine whether the user canceled an edit operation. Para cancelar una operación de inserción, establezca Cancel la propiedad trueen.To cancel an insert operation, set the Cancel property to true.

Para obtener más información acerca de cómo controlar eventos, vea controlar y provocar eventos.For more information about how to handle events, see Handling and Raising Events.

Para obtener una lista con los valores de propiedad iniciales de una instancia de la clase DetailsViewModeEventArgs, vea el constructor DetailsViewModeEventArgs.For a list of initial property values for an instance of the DetailsViewModeEventArgs class, see the DetailsViewModeEventArgs constructor.

Constructores

DetailsViewModeEventArgs(DetailsViewMode, Boolean)

Inicializa una nueva instancia de la clase DetailsViewModeEventArgs.Initializes a new instance of the DetailsViewModeEventArgs class.

Propiedades

Cancel

Obtiene o establece un valor que indica si se debe cancelar el evento.Gets or sets a value indicating whether the event should be canceled.

(Heredado de CancelEventArgs)
CancelingEdit

Obtiene un valor que indica si el evento ModeChanging se generó cuando el usuario canceló una operación de edición.Gets a value indicating whether the ModeChanging event was raised as a result of the user canceling an edit operation.

NewMode

Obtiene o establece el modo al que cambiará el control DetailsView.Gets or sets the mode to which the DetailsView control is changing.

Métodos

Equals(Object)

Determina si el objeto especificado es igual que el objeto actual.Determines whether the specified object is equal to the current object.

(Heredado de Object)
GetHashCode()

Sirve como función hash predeterminada.Serves as the default hash function.

(Heredado de Object)
GetType()

Obtiene el Type de la instancia actual.Gets the Type of the current instance.

(Heredado de Object)
MemberwiseClone()

Crea una copia superficial del objeto Object actual.Creates a shallow copy of the current Object.

(Heredado de Object)
ToString()

Devuelve una cadena que representa el objeto actual.Returns a string that represents the current object.

(Heredado de Object)

Se aplica a

Consulte también: