LinqDataSourceSelectEventArgs.SelectParameters Property

Definition

Gets the collection of parameters that is used to create the Select clause.

public:
 property System::Collections::Generic::IDictionary<System::String ^, System::Object ^> ^ SelectParameters { System::Collections::Generic::IDictionary<System::String ^, System::Object ^> ^ get(); };
public System.Collections.Generic.IDictionary<string,object> SelectParameters { get; }
member this.SelectParameters : System.Collections.Generic.IDictionary<string, obj>
Public ReadOnly Property SelectParameters As IDictionary(Of String, Object)

Property Value

An object that contains the parameters for the Select clause.

Examples

The following example shows how to add a parameter to the SelectParameters collection. The added parameter is used to calculate an adjusted price for a product based on whether products are on discounted. The first part of the example shows the event handler for the Selecting event.

protected void LinqDataSource_Selecting(object sender, LinqDataSourceSelectEventArgs e)
{
    if (IsOnlineSale)
    {
        e.SelectParameters.Add("Discount", OnlineDiscount);
    }
    else
    {
        e.SelectParameters.Add("Discount", 0);
    }
}
Protected Sub LinqDataSource_Selecting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.LinqDataSourceSelectEventArgs)
    If (IsOnlineSale) Then
        e.SelectParameters.Add("Discount", OnlineDiscount)
    Else
        e.SelectParameters.Add("Discount", 0)
    End If
End Sub

The second part of the example shows the markup that defines the Select clause.

<asp:LinqDataSource 
    ContextTypeName="ExampleDataContext" 
    TableName="Products" 
    AutoGenerateWhereClause="true"
    Select="new(Name, Price * (1 - @Discount) As OnlinePrice)"
    OnSelecting="LinqDataSource_Selecting" 
    ID="LinqDataSource1" 
    runat="server">
</asp:LinqDataSource>
<asp:GridView 
    DataSourceID="LinqDataSource1" 
    ID="GridView1" 
    runat="server">
</asp:GridView>
<asp:LinqDataSource 
    ContextTypeName="ExampleDataContext" 
    TableName="Products"            
    Select="new(Name, Price * (1 - @Discount) As OnlinePrice)"
    OnSelecting="LinqDataSource_Selecting" 
    ID="LinqDataSource1" 
    runat="server">
</asp:LinqDataSource>
<asp:GridView 
    DataSourceID="LinqDataSource1" 
    ID="GridView1" 
    runat="server">
</asp:GridView>

Remarks

You use the SelectParameters property to access parameters for the Select clause in a handler for the Selecting event. You can modify the Select clause by adding or removing parameters from this collection. By default, the SelectParameters property of the LinqDataSourceSelectEventArgs object contains any parameters that you added to the SelectParameters of the LinqDataSource control.

Applies to

See also