System.Web.UI.WebControls Namespace
Provides data for the SortCommand event of a DataGrid control.
A SortCommand event is raised whenever any of the LinkButton controls used for sorting a DataGrid is clicked.
Information associated with the SortCommand event is summed up in a DataGridSortCommandEventArgs object, that is made accessible to the designated event handler.
This information includes the source of the command and the expression by which to set the order of the data in the grid.
For a list of initial property values for an instance of DataGridSortCommandEventArgs, see the DataGridSortCommandEventArgs constructor.
For more information about handling events, see Web Forms Events Model.
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
DataGrid AllowSorting DataGridSortCommandEventHandler