asp.net.ph

GridView.SortExpression Property

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.

Syntax


Script GridView.SortExpression [ = strFieldName ]

Property Value


strFieldName The field name or expression to sort the GridView by.

The property is read/write with no default value.

Remarks

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.

Example

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;
}
  C# VB
Run Sample | View Source
See Also

GridView Members   GridViewSortEventArgs   SortDirection   Adding Sorting to a GridView Control Skip Navigation Links




Home
Suggested Reading


Previous page Back to top Next page

© 2000-2010 Rey Nuñez All rights reserved.

If you have any question, comment or suggestion
about this site, please send us a note

You can help support asp.net.ph