ListViewSortEventArgs Class
Provides data for the Sorting event.
Assembly: System.Web.Extensions (in System.Web.Extensions.dll)
System.EventArgs
System.ComponentModel.CancelEventArgs
System.Web.UI.WebControls.ListViewSortEventArgs
| Name | Description | |
|---|---|---|
![]() | ListViewSortEventArgs(String, SortDirection) | Initializes a new instance of the ListViewSortEventArgs class. |
| Name | Description | |
|---|---|---|
![]() | Cancel | Gets or sets a value indicating whether the event should be canceled.(Inherited from CancelEventArgs.) |
![]() | SortDirection | Gets or sets the direction in which to sort the ListView control. |
![]() | SortExpression | Gets or sets the expression that is used to sort the items in the ListView control. |
| Name | Description | |
|---|---|---|
![]() | Equals(Object) | Determines whether the specified object is equal to the current object.(Inherited from Object.) |
![]() | Finalize() | Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.(Inherited from Object.) |
![]() | GetHashCode() | Serves as the default hash function. (Inherited from Object.) |
![]() | GetType() | |
![]() | MemberwiseClone() | |
![]() | ToString() | Returns a string that represents the current object.(Inherited from Object.) |
The ListView control raises the Sorting event when a Sort button is clicked, but before the ListView control handles the sort operation. (A Sort button is a button whose CommandName property set to "Sort".) This enables you to provide an event-handling method that performs a custom routine whenever this event occurs, such as customizing the sort expression.
A ListViewSortEventArgs object is passed to the event-handling method. This object enables you to specify or determine the sort expression and sort direction for the ListView control. To determine the sort expression, use the SortExpression property. To determine the sort direction, use the SortDirection property. You can also cancel a sorting operation by setting the Cancel property to true.
For a list of initial property values for an instance of the ListViewSortEventArgs class, see the ListViewSelectEventArgs constructor.
The following example shows how to use the ListViewSortEventArgs object to display the sort direction and the column that is being sorted.
<%@ 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 ContactsListView_Sorting(ByVal sender As Object, ByVal e As ListViewSortEventArgs) ' Check the sort direction to set the image URL accordingly. Dim imgUrl As String If e.SortDirection = SortDirection.Ascending Then imgUrl = "~/images/ascending.gif" Else imgUrl = "~/images/descending.gif" End If ' Check which field is being sorted ' to set the visibility of the image controls. Dim sortImage1 As Image = CType(ContactsListView.FindControl("SortImage1"), Image) Dim sortImage2 As Image = CType(ContactsListView.FindControl("SortImage2"), Image) Dim sortImage3 As Image = CType(ContactsListView.FindControl("SortImage3"), Image) Select Case e.SortExpression Case "FirstName" sortImage1.Visible = True sortImage1.ImageUrl = imgUrl sortImage2.Visible = False sortImage3.Visible = False Case "LastName" sortImage1.Visible = False sortImage2.Visible = True sortImage2.ImageUrl = imgUrl sortImage3.Visible = False Case "EmailAddress" sortImage1.Visible = False sortImage2.Visible = False sortImage3.Visible = True sortImage3.ImageUrl = imgUrl End Select End Sub </script> <html xmlns="http://www.w3.org/1999/xhtml" > <head id="Head1" runat="server"> <title>ListView Sorting Example</title> <style type="text/css"> body { font: 10pt Trebuchet MS, Arial, Tahoma; } td { border: 1px solid #E6E6FA; } .header { background: #B0C4DE; } .alternatingItem { background: #edf5fd; } </style> </head> <body> <form id="form1" runat="server"> <h3>ListView Sorting Example</h3> <asp:ListView ID="ContactsListView" DataSourceID="ContactsDataSource" OnSorting="ContactsListView_Sorting" runat="server"> <LayoutTemplate> <table width="640px" runat="server" id="tblContacts"> <tr class="header" align="center" runat="server"> <td> <asp:LinkButton runat="server" ID="SortByFirstNameButton" CommandName="Sort" Text="First Name" CommandArgument="FirstName"/> <asp:Image runat="server" ID="SortImage1" ImageUrl="~/images/ascending.gif" Visible="false" /> </td> <td> <asp:LinkButton runat="server" ID="SortByLastNameButton" CommandName="Sort" Text="Last Name" CommandArgument="LastName" /> <asp:Image runat="server" ID="SortImage2" ImageUrl="~/images/ascending.gif" Visible="false" /> </td> <td> <asp:LinkButton runat="server" ID="SortByEmailButton" CommandName="Sort" Text="E-mail Address" CommandArgument="EmailAddress" /> <asp:Image runat="server" ID="SortImage3" ImageUrl="~/images/ascending.gif" Visible="false" /> </td> </tr> <tr runat="server" id="itemPlaceholder" /> </table> <asp:DataPager runat="server" ID="PeopleDataPager" PageSize="12"> <Fields> <asp:NextPreviousPagerField ShowFirstPageButton="true" ShowLastPageButton="true" FirstPageText="|<< " LastPageText=" >>|" NextPageText=" > " PreviousPageText=" < " /> </Fields> </asp:DataPager> </LayoutTemplate> <ItemTemplate> <tr runat="server"> <td> <asp:Label ID="FirstNameLabel" runat="server" Text='<%#Eval("FirstName") %>' /> </td> <td> <asp:Label ID="LastNameLabel" runat="server" Text='<%#Eval("LastName") %>' /> </td> <td> <asp:Label ID="EmailLabel" runat="server" Text='<%#Eval("EmailAddress") %>' /> </td> </tr> </ItemTemplate> <AlternatingItemTemplate> <tr class="alternatingItem" runat="server"> <td> <asp:Label ID="FirstNameLabel" runat="server" Text='<%#Eval("FirstName") %>' /> </td> <td> <asp:Label ID="LastNameLabel" runat="server" Text='<%#Eval("LastName") %>' /> </td> <td> <asp:Label ID="EmailLabel" runat="server" Text='<%#Eval("EmailAddress") %>' /> </td> </tr> </AlternatingItemTemplate> </asp:ListView> <!-- This example uses Microsoft SQL Server and connects --> <!-- to the AdventureWorks sample database. Use an ASP.NET --> <!-- expression to retrieve the connection string value --> <!-- from the Web.config file. --> <asp:SqlDataSource ID="ContactsDataSource" runat="server" ConnectionString="<%$ ConnectionStrings:AdventureWorks_DataConnectionString %>" SelectCommand="SELECT [ContactID], [FirstName], [LastName], [EmailAddress] FROM Person.Contact" > </asp:SqlDataSource> </form> </body> </html>
Available since 3.5
Any public static ( Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
.jpeg?cs-save-lang=1&cs-lang=vb)
.jpeg?cs-save-lang=1&cs-lang=vb)
.jpeg?cs-save-lang=1&cs-lang=vb)