LinqDataSource::OrderBy Property


The .NET API Reference documentation has a new home. Visit the .NET API Browser on to see the new experience.

Gets or sets a value that specifies which fields are used for ordering the retrieved data.

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

property String^ OrderBy {
	String^ get();
	void set(String^ value);

Property Value

Type: System::String^

A string that is used to create the Order By clause.

You use the OrderBy property to specify which properties from the returned data to use for sorting. The property for sorting the data must exist in the original data source, but it does not have to be included in the Select property. You can add a space and Ascending, ASC, Descending, or DESC to a property in the OrderBy string in order to specify how the ordered data is returned.

You can provide more than one property in the OrderBy property by separating each property by using a comma. For example, to order by properties named LastName and FirstName, set the OrderBy property to "LastName, FirstName".


When you use the LinqDataSource control with SQL Server 2000 or SQL Server Compact 3.5 and the AutoPage property is set to true, you must provide a value in the OrderBy property. By default, the AutoPage property is true. If you assign a value to the Select property, you must also include all identity columns in the list of properties that is returned in the query.

If the AutoSort property is set to true, a data-bound control can pass a sort expression to the LinqDataSource control at run time. The LinqDataSource control will apply the sort expression from the data-bound control after it applies the OrderBy property. Therefore, the data is returned according to the sort expression from the data-bound control.

The following example returns data in reverse alphabetical order based on values in the Category property.

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

.NET Framework
Available since 3.5
Return to top