GridViewSortEventArgs Classe
Définition
Important
Certaines informations portent sur la préversion du produit qui est susceptible d’être en grande partie modifiée avant sa publication. Microsoft exclut toute garantie, expresse ou implicite, concernant les informations fournies ici.
Fournit des données pour l'événement Sorting.
public ref class GridViewSortEventArgs : System::ComponentModel::CancelEventArgs
public class GridViewSortEventArgs : System.ComponentModel.CancelEventArgs
type GridViewSortEventArgs = class
inherit CancelEventArgs
Public Class GridViewSortEventArgs
Inherits CancelEventArgs
- Héritage
Exemples
L’exemple suivant montre comment utiliser l’objet GridViewSortEventArgs passé à la méthode de gestion des événements pour annuler l’opération de tri lorsque l’utilisateur tente de trier la colonne d’adresse dans un GridView contrôle.
<%@ 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>
Remarques
Le GridView contrôle déclenche l’événement Sorting lorsqu’un bouton Trier (un bouton dont la CommandName propriété est définie sur « Trier ») est cliqué, mais avant que le GridView contrôle gère l’opération de tri. Cela vous permet de fournir une méthode de gestion des événements qui effectue une routine personnalisée, telle que l’annulation de l’opération de tri, chaque fois que cet événement se produit.
Note
Bien que n’importe quel bouton d’un GridView contrôle dont la CommandName propriété est définie sur « Sort » déclenche l’événement Sorting , les boutons Trier apparaissent généralement dans la ligne d’en-tête d’un GridView contrôle.
Un GridViewSortEventArgs objet est passé à la méthode de gestion des événements, qui vous permet de spécifier ou de déterminer l’expression de tri et la direction de tri dans laquelle trier le GridView contrôle. Pour déterminer l’expression de tri, utilisez la SortExpression propriété. Pour déterminer le sens de tri, utilisez la SortDirection propriété. Vous pouvez également annuler une opération de tri en définissant la Cancel propriété sur true.
Pour plus d’informations sur la gestion des événements, consultez Gestion et déclenchement d’événements.
Pour obtenir la liste des valeurs de propriété initiales d’une instance de GridViewSortEventArgs, consultez le GridViewSelectEventArgs constructeur.
Constructeurs
| Nom | Description |
|---|---|
| GridViewSortEventArgs(String, SortDirection) |
Initialise une nouvelle instance de la classe GridViewSortEventArgs. |
Propriétés
| Nom | Description |
|---|---|
| Cancel |
Obtient ou définit une valeur indiquant si l’événement doit être annulé. (Hérité de CancelEventArgs) |
| SortDirection |
Obtient ou définit la direction dans laquelle trier le GridView contrôle. |
| SortExpression |
Obtient ou définit l’expression utilisée pour trier les éléments dans le GridView contrôle. |
Méthodes
| Nom | Description |
|---|---|
| Equals(Object) |
Détermine si l’objet spécifié est égal à l’objet actuel. (Hérité de Object) |
| GetHashCode() |
Sert de fonction de hachage par défaut. (Hérité de Object) |
| GetType() |
Obtient la Type de l’instance actuelle. (Hérité de Object) |
| MemberwiseClone() |
Crée une copie superficielle du Objectactuel. (Hérité de Object) |
| ToString() |
Retourne une chaîne qui représente l’objet actuel. (Hérité de Object) |