LinqDataSource.SelectParameters Propriedade

Definição

Obtém a coleção de parâmetros usados durante uma operação de recuperação de dados.Gets the collection of parameters that are used during a data-retrieval operation.

public:
 property System::Web::UI::WebControls::ParameterCollection ^ SelectParameters { 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 SelectParameters { get; }
[<System.ComponentModel.Browsable(false)>]
[<System.Web.UI.PersistenceMode(System.Web.UI.PersistenceMode.InnerProperty)>]
member this.SelectParameters : System.Web.UI.WebControls.ParameterCollection
Public ReadOnly Property SelectParameters As ParameterCollection

Valor da propriedade

ParameterCollection

Os parâmetros usados para criar a cláusula Select.The parameters that are used to create the Select clause.

Atributos

Exemplos

O exemplo a seguir mostra como usar um valor fornecido pelo usuário para calcular um valor nos dados retornados.The following example shows how to use a user-supplied value to calculate a value in the returned data. O usuário pode inserir um valor na caixa de texto que representa o número de dias de fabricação.The user can enter a value in the text box that represents the number of manufacturing days. Esse valor é dividido por um valor de um banco de dados que representa o número de dias para fabricar um produto.That value is divided by a value from a database that represents the number of days to manufacture a product. O valor retornado indica quantos produtos podem ser fabricados durante o número de dias especificado.The returned value indicates how many products can be manufactured during the specified number of days. A entrada do usuário é incluída no comando SELECT por meio da SelectParameters coleção.The user's input is included in the Select command through the SelectParameters collection.

Enter number of manufacturing days:
<asp:TextBox Text="1" ID="TextBox1" runat="server"></asp:TextBox><br />
<asp:Button ID="Button1" runat="server" Text="Refresh" /><br />
<asp:GridView ID="GridView1" runat="server" AllowPaging="True" 
    AllowSorting="True" AutoGenerateColumns="False" DataSourceID="LinqDataSource1">
    <Columns>
        <asp:boundfield DataField="Name" 
            HeaderText="Name" 
            ReadOnly="True" 
            SortExpression="Name">
        </asp:boundfield>
        <asp:boundfield DataField="NumberToManufacture" 
            HeaderText="Number to Manufacture" 
            ReadOnly="True" 
            SortExpression="NumberToManufacture">
        </asp:boundfield>
    </Columns>
</asp:GridView>
<asp:LinqDataSource 
    ContextTypeName="ExampleDataContext" 
    TableName="Products"
    Where="DaysToManufacture > 0 "
    Select="new (Name, @Days / DaysToManufacture As NumberToManufacture)" 
    ID="LinqDataSource1" 
    runat="server">
  <SelectParameters>
    <asp:ControlParameter 
        Type="Decimal" 
        Name="Days" 
        ControlID="TextBox1" 
        DefaultValue="1" />
  </SelectParameters>
</asp:LinqDataSource>
Enter number of manufacturing days:
<asp:TextBox Text="1" ID="TextBox1" runat="server"></asp:TextBox><br />
<asp:Button ID="Button1" runat="server" Text="Refresh" /><br />
<asp:GridView ID="GridView1" runat="server" AllowPaging="True" 
    AllowSorting="True" AutoGenerateColumns="False" DataSourceID="LinqDataSource1">
    <Columns>
        <asp:boundfield DataField="Name" 
            HeaderText="Name" 
            ReadOnly="True" 
            SortExpression="Name">
        </asp:boundfield>
        <asp:boundfield DataField="NumberToManufacture" 
            HeaderText="Number to Manufacture" 
            ReadOnly="True" 
            SortExpression="NumberToManufacture">
        </asp:boundfield>
    </Columns>
</asp:GridView>
<asp:LinqDataSource 
    ContextTypeName="ExampleDataContext" 
    TableName="Products"
    Where="DaysToManufacture > 0 "
    Select="new (Name, @Days / DaysToManufacture As NumberToManufacture)" 
    ID="LinqDataSource1" 
    runat="server">
  <SelectParameters>
    <asp:ControlParameter 
        Type="Decimal" 
        Name="Days" 
        ControlID="TextBox1" 
        DefaultValue="1" />
  </SelectParameters>
</asp:LinqDataSource>

Comentários

O LinqDataSource controle usa parâmetros na SelectParameters coleção para criar a cláusula SELECT em tempo de execução.The LinqDataSource control uses parameters in the SelectParameters collection to create the Select clause at run time. Você adiciona parâmetros à SelectParameters coleção quando deseja usar valores de tempo de execução na cláusula SELECT.You add parameters to the SelectParameters collection when you want to use run-time values in the Select clause. Por exemplo, você pode adicionar um parâmetro à SelectParameters coleção para representar uma propriedade no perfil do usuário.For example, you can add a parameter to the SelectParameters collection to represent a property in the user's profile. Em seguida, você pode usar essa propriedade e um valor da fonte de dados para calcular um novo valor.You can then use that property and a value from the data source to calculate a new value.

Se você não precisar definir um valor em tempo de execução na cláusula SELECT, não precisará usar a SelectParameters coleção.If you do not have to set a value at run time in the Select clause, you do not have to use the SelectParameters collection. Você pode definir as propriedades a serem recuperadas na Select propriedade.You can define the properties to retrieve in the Select property. Por exemplo, para retornar os FirstName LastName valores e de uma tabela de banco de dados, defina Select como "FirstName, LastName" sem nenhum parâmetro.For example, to return the FirstName and LastName values from a database table, set Select to "FirstName, LastName" without any parameters.

Para definir valores na SelectParameters coleção, você adiciona um espaço reservado na Select propriedade para o parâmetro nomeado.To set values in the SelectParameters collection, you add a placeholder in the Select property for the named parameter. Na cláusula SELECT, preceda cada nome de parâmetro com o símbolo @.In the Select clause, preface each parameter name with the @ symbol.

Você não pode usar um parâmetro na SelectParameters coleção para representar um nome de propriedade.You cannot use a parameter in the SelectParameters collection to represent a property name. Para definir dinamicamente a Select propriedade como o nome de uma propriedade, crie um manipulador de eventos para Selecting o evento e personalize a Select propriedade conforme necessário.To dynamically set the Select property to the name of a property, create an event handler for the Selecting event and customize the Select property as needed.

Aplica-se a