Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

LinqDataSource.OrderByParameters Property

Gets the collection of parameters that are used to create the Order By clause.

Namespace:  System.Web.UI.WebControls
Assembly:  System.Web.Extensions (in System.Web.Extensions.dll)
'Declaration
<PersistenceModeAttribute(PersistenceMode.InnerProperty)> _
<BrowsableAttribute(False)> _
Public ReadOnly Property OrderByParameters As ParameterCollection

Property Value

Type: System.Web.UI.WebControls.ParameterCollection
The parameters that are used for creating the Order By clause.

The LinqDataSource control uses parameters in the OrderByParameters collection to create the Order By clause at run time. Typically you set the AutoGenerateOrderByClause property to true when you add parameters to the OrderByParameters collection. When the AutoGenerateOrderByClause property is set to true, each parameter in the OrderByParameters collection is added to the Order By clause in the sequence that they are specified in the OrderByParameters collection. When the AutoGenerateOrderByClause property is true, the parameters do not have to be named because they are applied in sequence and are not matched to a placeholder.

If you do not have to set a value at run time in the Order By clause, you do not have to use the OrderByParameters collection. You can define the fields to use for ordering the data in the OrderBy property. For example, to return values from a database table ordered by LastName, set OrderBy to "LastName" without any parameters.

You can set parameters in the OrderByParameters collection and match the parameters to placeholders in the OrderBy property, but this approach has limited application. When you use this approach, the parameters in the OrderByParameters collection cannot represent a column name. You can set a parameter to a value and then compare that value to values in a property. For example, you can order the data based on whether the values in a property are less than the run-time value represented by the parameter.

The following example shows a LinqDataSource control with the AutoGenerateOrderByClause property set to true. A parameter is included in the OrderByParameters collection that orders the data based on the property name that a user selects from a DropDownList control.

<asp:DropDownList AutoPostBack="true" ID="DropDownList1" runat="server">
    <asp:ListItem Value="Category"></asp:ListItem>
    <asp:ListItem Value="Price"></asp:ListItem>
</asp:DropDownList>
<asp:LinqDataSource 
    ContextTypeName="ExampleDataContext" 
    TableName="Products" 
    AutoGenerateOrderByClause="true"
    ID="LinqDataSource1" 
    runat="server">
    <OrderByParameters>
      <asp:ControlParameter
         ControlID="DropDownList1" 
         Type="String" />
    </OrderByParameters>
</asp:LinqDataSource>
<asp:GridView 
    DataSourceID="LinqDataSource1"
    ID="GridView1" 
    runat="server">
</asp:GridView>

.NET Framework

Supported in: 4.5.1, 4.5, 4, 3.5

Windows Phone 8.1, Windows Phone 8, Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

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

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.