LinqDataSource.AutoSort 屬性

定義

取得或設定值,指出 LinqDataSource 控制項是否支援在執行階段排序資料。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

屬性值

Boolean

如果使用者可以排序資料,則為 true;否則為 falsetrue if the user can sort the data; otherwise, false. 預設值是 trueThe default value is true.

範例

下列範例顯示 LinqDataSource AutoSort 屬性設為的控制項 true ,以及系結 GridView 至控制項的控制項 LinqDataSourceThe following example shows a LinqDataSource control with the AutoSort property set to true and a GridView control that is bound to the LinqDataSource control. AllowSorting控制項的屬性 GridView 設定為, true 以提供可讓使用者排序資料的介面。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>

備註

LinqDataSource控制項支援兩種排序資料的方法。The LinqDataSource control supports two approaches for sorting data. 您可以使用 AutoSort 屬性來啟用執行時間排序,也可以設定 OrderBy 屬性來定義設計階段的排序。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.

AutoSort 屬性設為, trueLinqDataSource 根據資料繫結控制項中的排序運算式,在控制項中啟用排序。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.

您可以藉由將 OrderBy 屬性設定為用於排序的屬性或屬性,以程式設計方式設定傳回資料的順序。You can programmatically set the order in which data is returned by setting the OrderBy property to the property or properties used for sorting. OrderBy 屬性設定為屬性且 AutoSort 屬性為時 true ,會在屬性中的運算式之後套用資料繫結控制項的排序運算式 OrderByWhen 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.

適用於