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

Binding RadCombox with checkboxes

4 Answers 259 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Frank Luswata
Top achievements
Rank 1
Frank Luswata asked on 13 Oct 2011, 11:22 AM

How do i bind the concatenated texts of all checked item of the RadComboBox to a field in the SQLDatasource using the selectedvalue property? Am using the ASP.NET AJAX RadControls Q2 2011. 

An example would be very welcome.

4 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 13 Oct 2011, 01:42 PM
Hello Frank Luswata,

You can get the concatenated value by the following code. Then you can insert the value using simple query.

C#:
protected void RadComboBox1_SelectedIndexChanged(object sender,Telerik.Web.UI.RadComboBoxSelectedIndexChangedEventArgs e)
 {
   String s = RadComboBox1.Text;
 }

Thanks,
Princy.
0
Kalina
Telerik team
answered on 13 Oct 2011, 02:12 PM
Hi Frank Luswata,

What is the exact scenario that you want to implement?
Could you please explain it in more details and paste here some simplified code to illustrate it?

Best wishes,
Kalina
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
0
Frank Luswata
Top achievements
Rank 1
answered on 13 Oct 2011, 03:27 PM

Hi Kalina, 

The scenario is that I have a RadcomboBox inside an insert template of a formview. The formview is bound to an SqlDataSource for inserting with two fields ItemId, ItemsSelected into a table.

The selectedvalue of the RadcomboBox is bound to the field ItemsSelected. The dropp down values for the RadCombobox are selected from another table using another SqlDataSource. More than one item can be selected separated with commas using checkboxes=true. This works fine.

The challenge is that when the insert button is click record, only the DataValueField of the first selected item is inserted into the table. How can I get it to insert the concatenated items (i.e all ticked items). The code is attached.

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="Test_Default" %>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
     <telerik:RadScriptManager ID="RadScriptManager1" Runat="server">
    </telerik:RadScriptManager>
    <div>
    
        <br />
        <asp:FormView ID="FormView1" runat="server" DataSourceID="SqlDataSource1" 
            DefaultMode="Insert" Height="76px" Width="425px" DataKeyNames="ItemId">
            <InsertItemTemplate>
                ItemId:
                <asp:TextBox ID="ItemIdTextBox" runat="server" Text='<%# Bind("ItemId") %>' />
                <br />
                ItemsSelected:
                <telerik:RadComboBox ID="RadComboBox1" runat="server" 
                    DataSourceID="SqlDataSource2" DataTextField="Source" 
                    DataValueField="SourceId" CheckBoxes="True" 
                    SelectedValue='<%# Bind("ItemsSelected") %>'>
                </telerik:RadComboBox>
                <br />
                <asp:LinkButton ID="InsertButton" runat="server" CausesValidation="True" 
                    CommandName="Insert" Text="Insert" />
                &nbsp;<asp:LinkButton ID="InsertCancelButton" runat="server" 
                    CausesValidation="False" CommandName="Cancel" Text="Cancel" />
            </InsertItemTemplate>
        </asp:FormView>
        <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
            ConnectionString="<%$ ConnectionStrings:CSFMonitoringConnectionString %>" 
            DeleteCommand="DELETE FROM [TestTable] WHERE [ItemId] = @ItemId" 
            InsertCommand="INSERT INTO [TestTable] ([ItemId], [ItemsSelected]) VALUES (@ItemId, @ItemsSelected)" 
            SelectCommand="SELECT [ItemId], [ItemsSelected] FROM [TestTable]" 
            UpdateCommand="UPDATE [TestTable] SET [ItemsSelected] = @ItemsSelected WHERE [ItemId] = @ItemId">
            <DeleteParameters>
                <asp:Parameter Name="ItemId" Type="Int32" />
            </DeleteParameters>
            <UpdateParameters>
                <asp:Parameter Name="ItemsSelected" Type="String" />
                <asp:Parameter Name="ItemId" Type="Int32" />
            </UpdateParameters>
            <InsertParameters>
                <asp:Parameter Name="ItemId" Type="Int32" />
                <asp:Parameter Name="ItemsSelected" Type="String" />
            </InsertParameters>
        </asp:SqlDataSource>
        <br />


    </div>
                <asp:SqlDataSource ID="SqlDataSource2" runat="server" 
                    ConnectionString="<%$ ConnectionStrings:CSFMonitoringConnectionString %>" 
            SelectCommand="SELECT [SourceId], [Source] FROM [tblInfoSource]">
                </asp:SqlDataSource>
    </form>
</body>
</html>

0
Accepted
Princy
Top achievements
Rank 2
answered on 14 Oct 2011, 08:32 AM
Hello Frank Luswata,

I also faced the same issue when I tried with the SelectedValue same like that of your code. To overcome this just bind the Text property instead of SelectedValue of RadComboBox.

ASPX:
<telerik:RadComboBox ID="RadComboBox1" runat="server" DataSourceID="SqlDataSource1" DataTextField="CustomerID" DataValueField="CustomerID" CheckBoxes="True" Text='<%# Bind("ItemsSelected") %>'  >
</telerik:RadComboBox>

If you still want to bind the SelectedValue property, then another approach is to attach LinkButton click event and  store the RadComboBox text in a session variable and pass it as a session parameter. Here is the code.

ASPX:
<InsertParameters>
  <asp:Parameter Name="CustomerID" Type="Int32" />
  <asp:SessionParameter Name="sessionnm" DbType="String" SessionField="sessionnm" />
</InsertParameters>

C#:
protected void InsertButton_Click(object sender, EventArgs e)
{
   FormViewRow row = FormView1.Row;
   RadComboBox rbx = (RadComboBox)row.FindControl("RadComboBox1");
   Session["sessionnm"] = rbx.Text;
}

Thanks,
Princy.
Tags
ComboBox
Asked by
Frank Luswata
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Kalina
Telerik team
Frank Luswata
Top achievements
Rank 1
Share this question
or