OrderByExpression 類別

定義

提供方法,將排序運算式套用至 IQueryable 物件。Provides a way to apply a sort expression to an IQueryable object.

public ref class OrderByExpression : System::Web::UI::WebControls::Expressions::DataSourceExpression
public class OrderByExpression : System.Web.UI.WebControls.Expressions.DataSourceExpression
type OrderByExpression = class
    inherit DataSourceExpression
Public Class OrderByExpression
Inherits DataSourceExpression
繼承
OrderByExpression

範例

下列範例示範如何在 AdventureWorks 資料庫的 products 資料表中搜尋名稱開頭為SearchTextBox文字方塊中指定之字串的產品。The following example shows how to search the Products table of the AdventureWorks database for products that have names that start with the string that is specified in the SearchTextBox text box. OrderByExpression物件會依 ListPrice 資料欄位以遞減順序排序資料, 然後依照 [產品識別碼] 欄位以遞增順序排序。The OrderByExpression object sorts the data by the ListPrice data field in descending order and then by the product ID field in ascending order. LinqDataSource控制項傳回的查詢結果會顯示GridView在控制項中。The result of the query that is returned from the LinqDataSource control is displayed in a GridView control.

這個程式碼範例是在逐步解說中提供的較大範例的一部分:使用宣告式語法在網頁中篩選資料。This code example is part of a larger example that is provided in Walkthrough: Filtering Data in a Web Page Using Declarative Syntax.

備註

OrderByExpression類別會QueryExtender在控制項中用來以遞增或遞減順序排序資料。The OrderByExpression class is used in the QueryExtender control to sort data in ascending or descending order. 排序是由項目類型的預設比較子執行。The sorting is performed by the default comparer for the type of the element.

QueryExtender控制項支援各種不同的選項, 可讓您用來篩選資料。The QueryExtender control supports a variety of options that you can use to filter data. 使用篩選選項之後, 您可以使用OrderByExpression物件來排序資料。After you use the filter options, you can use the OrderByExpression object to sort the data.

您可以使用DataField屬性來指定要排序的資料欄位。You specify the data field to sort by using the DataField property. 您可以使用Direction屬性來指定排序方向。You specify the sort direction by using the Direction property. OrderByExpression物件套用至資料來源之後, 您可以ThenBy使用運算式, 在另一個資料欄位上執行後續的排序。After the OrderByExpression object has been applied to the data source, you can use the ThenBy expressions to perform a subsequent sort on another data field.

建構函式

OrderByExpression()

初始化 OrderByExpression 類別的新執行個體。Initializes a new instance of the OrderByExpression class.

屬性

Context

取得擁有者控制項的 HttpContext 執行個體。Gets the HttpContext instance of the owner control.

(繼承來源 DataSourceExpression)
DataField

取得或設定排序所依據之 IQueryable 物件的屬性。Gets or sets the property of the IQueryable object to sort by.

DataSource

取得與擁有者控制項相關聯的資料來源物件。Gets the data source object that is associated with the owner control.

(繼承來源 DataSourceExpression)
Direction

取得或設定 IQueryable 資料來源物件的排序方向。Gets or sets the sort direction of the IQueryable data source object.

IsTrackingViewState

取得值,這個值指出資料來源運算式物件是否正在追蹤其檢視狀態變更。Gets a value that indicates whether a data source expression object is tracking its view state changes.

(繼承來源 DataSourceExpression)
Owner

取得擁有者控制項。Gets the owner control.

(繼承來源 DataSourceExpression)
ThenByExpressions

取得或設定在將 ThenBy 值套用至資料來源之後要套用之 OrderByExpression 運算式的集合。Gets or sets the collection of ThenBy expressions to apply after an OrderByExpression value is applied to the data source.

ViewState

取得 StateBag 類別的執行個體,這個執行個體包含目前的檢視狀態資訊。Gets an instance of the StateBag class that contains the current view state information.

(繼承來源 DataSourceExpression)

方法

Equals(Object)

判斷指定的物件是否等於目前的物件。Determines whether the specified object is equal to the current object.

(繼承來源 Object)
GetHashCode()

做為預設雜湊函式。Serves as the default hash function.

(繼承來源 Object)
GetQueryable(IQueryable)

根據 IQueryable 值和 DataField 值,將排序運算式套用至 Direction 物件。Applies a sort expression to an IQueryable object based on a DataField value and a Direction value.

GetType()

取得目前執行個體的 TypeGets the Type of the current instance.

(繼承來源 Object)
LoadViewState(Object)

載入 DataSourceExpression 物件中必須保存的值狀態。Loads the state of the values in the DataSourceExpression object that must be persisted.

(繼承來源 DataSourceExpression)
MemberwiseClone()

建立目前 Object 的淺層複本 (Shallow Copy)。Creates a shallow copy of the current Object.

(繼承來源 Object)
SaveViewState()

儲存 DataSourceExpression 物件的目前檢視狀態。Saves the current view state of the DataSourceExpression object.

(繼承來源 DataSourceExpression)
SetContext(Control, HttpContext, IQueryableDataSource)

設定 DataSourceExpression 物件的 HTTP 內容,該物件會使用指定的擁有者控制項、HttpContext 執行個體和 IQueryableDataSource 物件。Sets the HTTP context of the DataSourceExpression object that uses the specified owner control, HttpContext instance, and IQueryableDataSource object.

(繼承來源 DataSourceExpression)
SetDirty()

標記 DataSourceExpression 物件,以便將其狀態儲存在檢視狀態中。Marks the DataSourceExpression object so that its state will be saved in view state.

(繼承來源 DataSourceExpression)
ToString()

傳回代表目前物件的字串。Returns a string that represents the current object.

(繼承來源 Object)
TrackViewState()

追蹤 DataSourceExpression 物件的檢視狀態變更,以便該變更可針對資料來源運算式物件儲存到 StateBag 物件中。Tracks view state changes of the DataSourceExpression object so that the changes can be stored in the StateBag object for the data source expression object.

(繼承來源 DataSourceExpression)

明確介面實作

IStateManager.IsTrackingViewState

當由類別實作時取得值,這個值指出資料來源運算式物件是否正在追蹤其檢視狀態變更。When implemented by a class, gets a value that indicates whether a data source expression object is tracking its view state changes.

(繼承來源 DataSourceExpression)
IStateManager.LoadViewState(Object)

當由類別實作時,載入資料來源運算式物件先前儲存的檢視狀態。When implemented by a class, loads the previously saved view state of the data source expression object.

(繼承來源 DataSourceExpression)
IStateManager.SaveViewState()

當類別實作時,儲存 DataSourceExpression 物件的目前檢視狀態。When implemented by a class, saves the current view state of the DataSourceExpression object.

(繼承來源 DataSourceExpression)
IStateManager.TrackViewState()

當由類別實作時,追蹤 DataSourceExpression 物件的檢視狀態變更,以便該變更可針對資料來源運算式物件儲存到 StateBag 物件中。When implemented by a class, tracks view state changes of the DataSourceExpression object so that the changes can be stored in the StateBag object for the data source expression object.

(繼承來源 DataSourceExpression)

適用於

另請參閱