System.Web.UI.WebControls Namespace GridView Class
.NET Framework version 2.0
Sets or retrieves the sort expression when a column in a GridView is selected for sorting.
Script |
GridView.SortExpression [ = strFieldName ] |
strFieldName |
The field name or expression to sort the GridView by. |
The property is read/write with no default value.
Use the SortExpression property to specify or determine the name of the field to pass to the Sorted or Sorting event handler when a column is selected for sorting.
When AutoGenerateColumns is true, the SortExpression property for each column in the GridView is automatically set to the field name bound to the column. Otherwise ( when AutoGenerateColumns is false ), you need to manually set the SortExpression property for each column that you want to enable sorting for.
The value of the SortExpression property for the selected column is passed to the SortCommand event handler as part of the GridViewSortEventArgs object.
When multiple columns are sorted, this property contains a comma-separated list of the fields by which to sort.
The following example demonstrates how to access the SortExpression property of a GridViewSortEventArgs object, to determine which column the user selected to sort the GridView control by.
void getSortParams ( Object src, GridViewSortEventArgs e ) {
msg.Text = "Current SortExpression: " + e.SortExpression;
msg.Text += ", SortDirection: " + e.SortDirection;
}
Sub getSortParams ( ByVal src as Object, ByVal e as GridViewSortEventArgs ) {
msg.Text = "Current SortExpression: " & e.SortExpression
msg.Text += ", SortDirection: " & e.SortDirection;
End Sub
|
|
C# |
VB |
GridView Members GridViewSortEventArgs SortDirection Adding Sorting to a GridView Control