correct event to override default value for SQLdatasource select param in radgrid

2 posts, 0 answers
  1. kellyroberts
    kellyroberts avatar
    45 posts
    Member since:
    Jul 2007

    Posted 17 Mar 2014 Link to this post

    Hi Folks - Apologies in advance, this may not be the best place to post.

    I have an ASP.NET 3.5 app.  I have a page with a multi-select listbox, a button, a radgrid and a SQL datasource.  The datasource has one param that looks sorta like this ...

    <asp:ControlParameter Name="Param1" ControlID="lstParam1" PropertyName="SelectedValue" />

    so, currently, without any extra code, only the first selected value from the listbox is passed to the sql datasource.

    I have code to make a comma sep list of the multi selected values, and I have a sproc for list_to_table type functionality so thats not the problem.

    Problem is that Im having a hard time finding the right event to use to override the default value of this param. 

    I can supply more markup/code if needed.

    Any help is appreciated ... apologies agian if Im using the wrong forum.
  2. Konstantin Dikov
    Konstantin Dikov avatar
    2083 posts

    Posted 20 Mar 2014 Link to this post

    Hello Kelly,

    Since you want to use a custom value and not the value from the SelectedValue property of another control, it will be more appropriate to use asp:Parameter instead.

    The following simple scenario demonstrates such approach:
    <telerik:RadComboBox runat="server" ID="RadComboBox1" AutoPostBack="true" OnSelectedIndexChanged="RadComboBox1_SelectedIndexChanged">
            <telerik:RadComboBoxItem Text="A" Value="A" />
            <telerik:RadComboBoxItem Text="B" Value="B" />
            <telerik:RadComboBoxItem Text="C" Value="C" />
    <telerik:RadGrid ID="RadGrid1" runat="server" DataSourceID="SqlDataSource1" PageSize="3" AllowPaging="true"></telerik:RadGrid>
    <asp:SqlDataSource runat="server" ID="SqlDataSource1" ConnectionString='<%$ ConnectionStrings:NorthwindConnectionString %>'
        SelectCommand="SELECT * FROM [Customers] WHERE CustomerID LIKE @CustomerName + '%'">
            <asp:Parameter Name="CustomerName" DefaultValue="A" />

    And the code-behind:
    protected void RadComboBox1_SelectedIndexChanged(object sender, RadComboBoxSelectedIndexChangedEventArgs e)
        SqlDataSource1.SelectParameters[0].DefaultValue = e.Value.ToString();

    Hope that helps.

    Konstantin Dikov

    Build cross-platform mobile apps using Visual Studio and .NET. Register for the online webinar on 03/27/2014, 11:00AM US ET.. Seats are limited.

Back to Top