This documentation is archived and is not being maintained.

LinqDataSource.SelectParameters Property

Gets the collection of parameters that are used during a data-retrieval operation.

Namespace:  System.Web.UI.WebControls
Assembly:  System.Web.Extensions (in System.Web.Extensions.dll)

public ParameterCollection SelectParameters { get; }

Property Value

Type: System.Web.UI.WebControls.ParameterCollection
The parameters that are used to create the Select clause.

The LinqDataSource control uses parameters in the SelectParameters collection to create the Select clause at run time. You add parameters to the SelectParameters collection when you want to use run-time values in the Select clause. For example, you can add a parameter to the SelectParameters collection to represent a property in the user's profile. You can then use that property and a value from the data source to calculate a new value.

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. You can define the properties to retrieve in the Select property. For example, to return the FirstName and LastName values from a database table, set Select to "FirstName, LastName" without any parameters.

To set values in the SelectParameters collection, you add a placeholder in the Select property for the named parameter. In the Select clause, preface each parameter name with the @ symbol.

You cannot use a parameter in the SelectParameters collection to represent a property name. 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.

The following example shows how to use a user-supplied value to calculate a value in the returned data. The user can enter a value in the text box that represents the number of manufacturing days. That value is divided by a value from a database that represents the number of days to manufacture a product. The returned value indicates how many products can be manufactured during the specified number of days. 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">
        <asp:boundfield DataField="Name" 
        <asp:boundfield DataField="NumberToManufacture" 
            HeaderText="Number to Manufacture" 
    Where="DaysToManufacture > 0 "
    Select="new (Name, @Days / DaysToManufacture As NumberToManufacture)" 
        DefaultValue="1" />

.NET Framework

Supported in: 4, 3.5

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

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