This documentation is archived and is not being maintained.

LinqDataSource.OrderBy Property

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)

public string OrderBy { get; set; }
<asp:LinqDataSource OrderBy="String" />

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.

    OrderBy="Category Descending"

Windows 7, Windows Vista, Windows XP SP2, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5