LinqDataSource.OrderByParameters Propriedade

Definição

Obtém a coleção de parâmetros usados para criar a cláusula Order By.Gets the collection of parameters that are used to create the Order By clause.

public:
 property System::Web::UI::WebControls::ParameterCollection ^ OrderByParameters { System::Web::UI::WebControls::ParameterCollection ^ get(); };
[System.ComponentModel.Browsable(false)]
[System.Web.UI.PersistenceMode(System.Web.UI.PersistenceMode.InnerProperty)]
public System.Web.UI.WebControls.ParameterCollection OrderByParameters { get; }
[<System.ComponentModel.Browsable(false)>]
[<System.Web.UI.PersistenceMode(System.Web.UI.PersistenceMode.InnerProperty)>]
member this.OrderByParameters : System.Web.UI.WebControls.ParameterCollection
Public ReadOnly Property OrderByParameters As ParameterCollection

Valor da propriedade

ParameterCollection

Os parâmetros que são usados para criar a cláusula order by.The parameters that are used for creating the Order By clause.

Atributos

Exemplos

O exemplo a seguir mostra um LinqDataSource controle com a AutoGenerateOrderByClause propriedade definida como true .The following example shows a LinqDataSource control with the AutoGenerateOrderByClause property set to true. Um parâmetro é incluído na OrderByParameters coleção que ordena os dados com base no nome da propriedade que um usuário seleciona em um DropDownList controle.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>
<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>

Comentários

O LinqDataSource controle usa parâmetros na OrderByParameters coleção para criar a cláusula order by em tempo de execução.The LinqDataSource control uses parameters in the OrderByParameters collection to create the Order By clause at run time. Normalmente, você define a AutoGenerateOrderByClause propriedade como true quando adiciona parâmetros à OrderByParameters coleção.Typically you set the AutoGenerateOrderByClause property to true when you add parameters to the OrderByParameters collection. Quando a AutoGenerateOrderByClause propriedade é definida como true , cada parâmetro na OrderByParameters coleção é adicionado à cláusula order by na sequência em que eles são especificados na OrderByParameters coleção.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. Quando a AutoGenerateOrderByClause propriedade é true , os parâmetros não precisam ser nomeados porque são aplicados em sequência e não correspondem a um espaço reservado.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.

Se você não precisar definir um valor em tempo de execução na cláusula order by, não será necessário usar a OrderByParameters coleção.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. Você pode definir os campos a serem usados para ordenar os dados na OrderBy propriedade.You can define the fields to use for ordering the data in the OrderBy property. Por exemplo, para retornar valores de uma tabela de banco de dados ordenada por LastName , defina OrderBy como "LastName" sem nenhum parâmetro.For example, to return values from a database table ordered by LastName, set OrderBy to "LastName" without any parameters.

Você pode definir parâmetros na OrderByParameters coleção e corresponder os parâmetros a espaços reservados na OrderBy propriedade, mas essa abordagem tem um aplicativo limitado.You can set parameters in the OrderByParameters collection and match the parameters to placeholders in the OrderBy property, but this approach has limited application. Quando você usa essa abordagem, os parâmetros na OrderByParameters coleção não podem representar um nome de coluna.When you use this approach, the parameters in the OrderByParameters collection cannot represent a column name. Você pode definir um parâmetro para um valor e, em seguida, comparar esse valor com valores em uma propriedade.You can set a parameter to a value and then compare that value to values in a property. Por exemplo, você pode ordenar os dados com base em se os valores em uma propriedade são menores do que o valor de tempo de execução representado pelo parâmetro.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.

Aplica-se a