編輯

共用方式為


LinqDataSource.AutoSort Property

Definition

Gets or sets a value that indicates whether the LinqDataSource control supports sorting the data at run time.

public:
 property bool AutoSort { bool get(); void set(bool value); };
public bool AutoSort { get; set; }
member this.AutoSort : bool with get, set
Public Property AutoSort As Boolean

Property Value

true if the user can sort the data; otherwise, false. The default value is true.

Examples

The following example shows a LinqDataSource control with the AutoSort property set to true and a GridView control that is bound to the LinqDataSource control. The AllowSorting property of the GridView control is set to true to provide the interface that lets users sort the data.

<asp:LinqDataSource 
    ContextTypeName="ExampleDataContext" 
    TableName="Products" 
    AutoPage="true"
    AutoSort="true"
    ID="LinqDataSource1" 
    runat="server">
</asp:LinqDataSource>
<asp:GridView 
    AllowPaging="true"
    AllowSorting="true"
    DataSourceID="LinqDataSource1"
    ID="GridView1" 
    runat="server">
</asp:GridView>
<asp:LinqDataSource 
    ContextTypeName="ExampleDataContext" 
    TableName="Products" 
    AutoPage="true"
    AutoSort="true"
    ID="LinqDataSource1" 
    runat="server">
</asp:LinqDataSource>
<asp:GridView 
    AllowPaging="true"
    AllowSorting="true"
    DataSourceID="LinqDataSource1"
    ID="GridView1" 
    runat="server">
</asp:GridView>

Remarks

The LinqDataSource control supports two approaches for sorting data. You can use the AutoSort property to enable run-time sorting or you can set the OrderBy property to define the sorting at design time.

Set the AutoSort property to true to enable sorting in a LinqDataSource control that is based on the sort expression from a data-bound control. The data-bound control provides the interface to enable the user to select at run time which property to use for sorting.

You can programmatically set the order in which data is returned by setting the OrderBy property to the property or properties used for sorting. When the OrderBy property is set to a property and the AutoSort property is true, the sort expression from the data-bound control is applied after the expression in the OrderBy property. Therefore, this determines the final sorting of the data.

Applies to