GridViewSortEventArgs GridViewSortEventArgs GridViewSortEventArgs GridViewSortEventArgs Class

Definición

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

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

Ejemplos

En el ejemplo siguiente se muestra cómo utilizar GridViewSortEventArgs el objeto pasado al método de control de eventos para cancelar la operación de ordenación cuando el usuario intenta ordenar la columna de dirección GridView en un control.The following example demonstrates how to use the GridViewSortEventArgs object passed to the event-handling method to cancel the sorting operation when the user attempts to sort the address column in a GridView control.


<%@ 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 CustomersGridView_Sorting(Object sender, GridViewSortEventArgs e)
  {
    // Cancel the sorting operation if the user attempts
    // to sort by address.
    if (e.SortExpression == "Address")
    {
      e.Cancel = true;
      Message.Text = "You cannot sort by address.";
      SortInformationLabel.Text = "";
    }
    else
    {
      Message.Text = "";
    }
  }

  void CustomersGridView_Sorted(Object sender, EventArgs e)
  {
    // Display the sort expression and sort direction.
    SortInformationLabel.Text = "Sorting by " +
      CustomersGridView.SortExpression.ToString() +
      " in " + CustomersGridView.SortDirection.ToString() +
      " order.";
  }
  
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>GridView Sorting Example</title>
</head>
<body>
    <form id="form1" runat="server">
        
      <h3>GridView Sorting Example</h3>

      <asp:label id="Message"
        forecolor="Red"
        runat="server"/>
        
      <br/>
        
      <asp:label id="SortInformationLabel"
        forecolor="Navy"
        runat="server"/>
                
      <br/>  

      <asp:gridview id="CustomersGridView" 
        datasourceid="CustomersSource" 
        autogeneratecolumns="true"
        allowpaging="true"
        emptydatatext="No data available." 
        allowsorting="true"
        onsorting="CustomersGridView_Sorting"
        onsorted="CustomersGridView_Sorted"  
        runat="server">
                
      </asp:gridview>
            
      <!-- 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="CustomersSource"
        selectcommand="Select [CustomerID], [CompanyName], [Address], [City], [PostalCode], [Country] From [Customers]"
        connectionstring="<%$ ConnectionStrings:NorthWindConnectionString%>" 
        runat="server"/>
        
    </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 CustomersGridView_Sorting(sender As Object, e As GridViewSortEventArgs)
  
    ' Cancel the sorting operation if the user attempts
    ' to sort by address.
    If e.SortExpression = "Address" Then
    
      e.Cancel = True
      Message.Text = "You cannot sort by address."
      SortInformationLabel.Text = ""
    
    Else
    
      Message.Text = ""
      
    End If
    
  End Sub

  Sub CustomersGridView_Sorted(ByVal sender As Object, ByVal e As EventArgs)
 
    ' Display the sort expression and sort direction.
    SortInformationLabel.Text = "Sorting by " & _
      CustomersGridView.SortExpression.ToString() & _
      " in " & CustomersGridView.SortDirection.ToString() & _
      " order."
    
  End Sub
    
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>GridView Sorted and Sorting Example</title>
</head>
<body>
    <form id="form1" runat="server">
        
      <h3>GridView Sorted and Sorting Example</h3>

      <asp:label id="Message"
        forecolor="Red"
        runat="server"/>
        
      <br/>
        
      <asp:label id="SortInformationLabel"
        forecolor="Navy"
        runat="server"/>
                
      <br/>  

      <asp:gridview id="CustomersGridView" 
        datasourceid="CustomersSource" 
        autogeneratecolumns="true"
        allowpaging="true"
        emptydatatext="No data available." 
        allowsorting="true"
        onsorting="CustomersGridView_Sorting"
        onsorted="CustomersGridView_Sorted"  
        runat="server">
                
      </asp:gridview>
            
      <!-- 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="CustomersSource"
        selectcommand="Select [CustomerID], [CompanyName], [Address], [City], [PostalCode], [Country] From [Customers]"
        connectionstring="<%$ ConnectionStrings:NorthWindConnectionString%>" 
        runat="server"/>
        
    </form>
  </body>
</html>

Comentarios

El GridView control provoca el Sorting evento cuando se hace clic en un botón de ordenación (un botón con su CommandName propiedad establecida en "Sort"), GridView pero antes de que el control administre la operación de ordenación.The GridView control raises the Sorting event when a Sort button (a button with its CommandName property set to "Sort") is clicked, but before the GridView control handles the sort operation. Esto le permite proporcionar un método de control de eventos que realiza una rutina personalizada, como cancelar la operación de ordenación, siempre que se produce este evento.This allows you to provide an event-handling method that performs a custom routine, such as canceling the sorting operation, whenever this event occurs.

Nota

Aunque cualquier botón de un GridView control con su CommandName propiedad establecida en "Sort" generará el Sorting evento, los botones de ordenación aparecen normalmente en la fila GridView de encabezado de un control.Although any button within a GridView control with its CommandName property set to "Sort" will raise the Sorting event, Sort buttons typically appear in the header row of a GridView control.

Un GridViewSortEventArgs objeto se pasa al método de control de eventos, que permite especificar o determinar la expresión de ordenación y la dirección de ordenación en la GridView que se va a ordenar el control.A GridViewSortEventArgs object is passed to the event-handling method, which allows you to specify or determine the sort expression and sort direction in which to sort the GridView control. Para determinar la expresión de ordenación, SortExpression use la propiedad.To determine the sort expression, use the SortExpression property. Para determinar la dirección de ordenación, SortDirection use la propiedad.To determine the sort direction, use the SortDirection property. También puede cancelar una operación de ordenación estableciendo la Cancel propiedad en. trueYou can also cancel a sorting operation by setting 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 de los valores de propiedad iniciales de GridViewSortEventArgsuna instancia de GridViewSelectEventArgs , vea el constructor.For a list of initial property values for an instance of GridViewSortEventArgs, see the GridViewSelectEventArgs constructor.

Constructores

GridViewSortEventArgs(String, SortDirection) GridViewSortEventArgs(String, SortDirection) GridViewSortEventArgs(String, SortDirection) GridViewSortEventArgs(String, SortDirection)

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

Propiedades

Cancel Cancel Cancel 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.

(Inherited from CancelEventArgs)
SortDirection SortDirection SortDirection SortDirection

Obtiene o establece la dirección en que se va a ordenar el control GridView.Gets or sets the direction in which to sort the GridView control.

SortExpression SortExpression SortExpression SortExpression

Obtiene o establece la expresión utilizada para ordenar los elementos del control GridView.Gets or sets the expression used to sort the items in the GridView control.

Métodos

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

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

(Inherited from Object)
GetHashCode() GetHashCode() GetHashCode() GetHashCode()

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

(Inherited from Object)
GetType() GetType() GetType() GetType()

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

(Inherited from Object)
MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

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

(Inherited from Object)
ToString() ToString() ToString() ToString()

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

(Inherited from Object)

Se aplica a

Consulte también: