System.Web.UI.WebControls Namespace DataGridColumn Class
Sets or retrieves the field name or expression to pass to the DataGridSortCommandEventHandler when a column is selected for sorting.
Script |
DataGridColumn.SortExpression [ = strFieldName ] |
strFieldName |
The field name or expression to sort the DataGridColumn 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 SortCommand event handler when a column is selected for sorting.
When AutoGenerateColumns is true, the SortExpression property for each column in the DataGrid is automatically set with 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 DataGridSortCommandEventArgs object.
The following example demonstrates how to access the SortExpression property of a DataGridSortCommandEventArgs object, to determine which column the user selected to sort the DataGrid control by.
void sortGrid ( Object src, DataGridSortCommandEventArgs e ) {
DataView myView = fetchData ( query, "northwind" ).Tables [ 0 ].DefaultView;
myView.Sort = e.SortExpression;
myGrid.DataSource = myView;
myGrid.DataBind ( );
}
Sub sortGrid ( src As Object, e As DataGridSortCommandEventArgs )
Dim myView As DataView = fetchData ( query, "northwind" ).Tables ( 0 ).DefaultView
myView.Sort = e.SortExpression
myGrid.DataSource = myView
myGrid.DataBind ( )
End Sub |
|
C# |
VB |
Show me
DataGridColumn Members DataGridSortCommandEventArgs DataGridSortCommandEventHandler