Gets the collection of parameters that are used during a data-retrieval operation.
Assembly: System.Web.Extensions (in System.Web.Extensions.dll)
The LinqDataSource control uses parameters in the collection to create the Select clause at run time. You add parameters to the collection when you want to use run-time values in the Select clause. For example, you can add a parameter to the 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 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 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 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 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>
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