DataGridColumn::SortExpression Property

 

Gets or sets the name of the field or expression to pass to the OnSortCommand method when a column is selected for sorting.

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

public:
property String^ SortExpression {
	virtual String^ get();
	virtual void set(String^ value);
}

Property Value

Type: System::String^

The name of the field to pass to OnSortCommand when a column is selected for sorting. The default value is String::Empty.

Use the SortExpression property to specify or determine the name of the field to pass to the OnSortCommand method when a column is selected for sorting.

System_CAPS_noteNote

This property does not bind the column to a field in data source. To bind a column to a field, see the documentation for the specific column type.

When sorting is enabled, LinkButton controls are rendered in the heading section of each column where the SortExpression property is set.

System_CAPS_noteNote

When the AutoGenerateColumns property is set to true, the SortExpression property for each column in the DataGrid control that supports data binding is automatically set with the field name bound to the column. If the AutoGenerateColumns property is set to false, you need to manually set the SortExpression property with the field name bound to the column for each column that you want to enable sorting for.

These LinkButton controls allow you to sort the DataGrid control by the selected column. When a LinkButton control for a column is clicked, the SortCommand event is raised. The value of the SortExpression property for the selected column is passed to the OnSortCommand event handler as part of the DataGridSortCommandEventArgs object.

The following code example demonstrates how to use the SortExpression property to specify the field name to use for sorting.

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

.NET Framework
Available since 1.1
Return to top
Show: