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 Select property. For example, to return the FirstName and LastName values from a database table, set Select to "FirstName, LastName" without any parameters.collection. You can define the properties to retrieve in the
To set values in the Select property for the named parameter. In the Select clause, preface each parameter name with the @ symbol.collection, you add a placeholder in the
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 thecollection.
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>
Available since 3.5