GridView.Sort Method

Sorts the GridView control based on the specified sort expression and direction.

Namespace: System.Web.UI.WebControls
Assembly: System.Web (in system.web.dll)

public:
virtual void Sort (
	String^ sortExpression, 
	SortDirection sortDirection
)
public void Sort (
	String sortExpression, 
	SortDirection sortDirection
)
public function Sort (
	sortExpression : String, 
	sortDirection : SortDirection
)
Not applicable.

Parameters

sortExpression

The sort expression with which to sort the GridView control.

sortDirection

One of the SortDirection values.

Use the Sort method to programmatically sort the GridView control using the specified sort expression and direction. The sort expression specifies the column or columns with which to sort. To sort multiple columns, create a sort expression that contains a comma-separated list of field names. The sort direction indicates whether sorting is performed in ascending or descending order. This method is commonly used when you need to sort the GridView control from outside of the control, such as from a different control on the page. This method is also commonly used to programmatically set a default sort order for the GridView control when it is first rendered. Calling this method also raises the Sorted and Sorting events.

The following code example demonstrates how to use the Sort method to programmatically sort the GridView control by multiple columns.

No code example is currently available or this language may not be supported.

Windows 98, Windows Server 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0

Community Additions

ADD
Show: