This is a migrated thread and some comments may be shown as answers.

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

1 Answer 202 Views
Grid
This is a migrated thread and some comments may be shown as answers.
kellyroberts
Top achievements
Rank 1
kellyroberts asked on 17 Mar 2014, 10:04 PM
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.

1 Answer, 1 is accepted

Sort by
0
Konstantin Dikov
Telerik team
answered on 20 Mar 2014, 03:00 PM
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">
    <Items>
        <telerik:RadComboBoxItem Text="A" Value="A" />
        <telerik:RadComboBoxItem Text="B" Value="B" />
        <telerik:RadComboBoxItem Text="C" Value="C" />
    </Items>
</telerik:RadComboBox>
 
<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 + '%'">
    <SelectParameters>
        <asp:Parameter Name="CustomerName" DefaultValue="A" />
    </SelectParameters>
</asp:SqlDataSource>

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

Hope that helps.


Regards,
Konstantin Dikov
Telerik
 

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.

 
Tags
Grid
Asked by
kellyroberts
Top achievements
Rank 1
Answers by
Konstantin Dikov
Telerik team
Share this question
or