Bewerken

Delen via


LinqDataSource.OrderBy Property

Definition

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

public:
 property System::String ^ OrderBy { System::String ^ get(); void set(System::String ^ value); };
public string OrderBy { get; set; }
member this.OrderBy : string with get, set
Public Property OrderBy As String

Property Value

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

Examples

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

<asp:LinqDataSource 
    ContextTypeName="ExampleDataContext" 
    TableName="Products" 
    OrderBy="Category Descending"
    ID="LinqDataSource1" 
    runat="server">
</asp:LinqDataSource>
<asp:GridView 
    AllowPaging="true"
    DataSourceID="LinqDataSource1"
    ID="GridView1" 
    runat="server">
</asp:GridView>
<asp:LinqDataSource 
    ContextTypeName="ExampleDataContext" 
    TableName="Products" 
    OrderBy="Category Descending"
    ID="LinqDataSource1" 
    runat="server">
</asp:LinqDataSource>
<asp:GridView 
    AllowPaging="true"
    DataSourceID="LinqDataSource1"
    ID="GridView1" 
    runat="server">
</asp:GridView>

Remarks

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".

Note

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.

Applies to