RadComboBox Multi-Select Checkboxes

2 posts, 0 answers
  1. Fawad
    Fawad avatar
    20 posts
    Member since:
    Nov 2014

    Posted 22 Nov 2014 Link to this post


    I have used RadComboBox inside my DetailsView. I send the value of combobox as comma separated to the database as (1,2,3,4). When I want to retrieve the data (1,2,3,4) from the database on edit mode of DetailsView, how can I set or bind the "Checked" values and display them as checked back in the combobox.

    Here is what i have done:


    <%----------------------- DATA SOURCE FOR DELIVERABLE -------------------------%>
    <asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:ITSConnectionString %>"
                DeleteCommand="DELETE FROM [Deliverable] WHERE [DeliverableId] = @DeliverableId"
                InsertCommand="INSERT INTO [Deliverable] ([DeliverableTitle],[CCIds]) VALUES (@DeliverableTitle, @CCIds)"
                SelectCommand="SELECT * FROM [Deliverable] WHERE ([DeliverableId] = @DeliverableId)"
                UpdateCommand="UPDATE [Deliverable] SET [DeliverableTitle] = @DeliverableTitle, [CCIds] = @CCIds WHERE [DeliverableId] = @DeliverableId">
                    <asp:Parameter Name="DeliverableId" Type="Int32" />
                    <asp:Parameter Name="DeliverableId" Type="int32" />
                    <asp:Parameter Name="DeliverableTitle" Type="String" />
                    <asp:Parameter Name="CCIds" Type="String" />
                    <asp:Parameter Name="DeliverableId" Type="int32" />
                    <asp:Parameter Name="DeliverableTitle" Type="String" />
                    <asp:Parameter Name="CCIds" Type="String" />
          <asp:QueryStringParameter Name="DeliverableId" QueryStringField="DeliverableId" Type="Int32" />
    <%----------------------- DATA SOURCE FOR COMBOBOX -------------------------%>
    <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ITSConnectionString %>" SelectCommand="SELECT [UserId], [DisplayName] FROM [Users]"></asp:SqlDataSource>
    <%----------------------- THE DETAILS VIEW -------------------------%>
    <asp:DetailsView ID="DetailsView1" runat="server" DefaultMode="Insert" AutoGenerateRows="False" DataKeyNames="DeliverableId" DataSourceID="SqlDataSource2" Height="50px" Width="125px" OnItemInserting="DetailsView1_ItemInserting" OnDataBinding="DetailsView1_DataBinding" OnDataBound="DetailsView1_DataBound">
                    <asp:BoundField DataField="DeliverableId" HeaderText="DeliverableId" InsertVisible="False" ReadOnly="True" SortExpression="DeliverableId" />
                    <asp:BoundField DataField="DeliverableId" HeaderText="DeliverableId" SortExpression="DeliverableId" />
                    <asp:BoundField DataField="DeliverableTitle" HeaderText="DeliverableTitle" SortExpression="DeliverableTitle"/>
                         <telerik:RadComboBox ID="CCIds" Text='<% #Bind("CCIds") %>' runat="server"
                             DataSourceID="SqlDataSource1" DataTextField="DisplayName"  DataValueField="UserId"
                    <asp:CommandField ShowEditButton="True" />
                    <asp:ButtonField Text="Insert" CommandName="Insert" />
                    <asp:ButtonField Text="Update" CommandName="Update" />

            public string GetCheckBoxValues(string RadComboBoxName)
                RadComboBox rcb = (RadComboBox)DetailsView1.FindControl(RadComboBoxName);
                var collection = rcb.CheckedItems;
                StringBuilder sbValues = new StringBuilder();
                if (collection.Count != 0)
                    foreach (var item in collection)
                    if (sbValues.ToString().EndsWith(Delimiter))
                        sbValues.Remove(sbValues.Length - 1, 1);
                return sbValues.ToString();
    // Get the comma separate values and insert them into the DB.
            protected void DetailsView1_ItemInserting(object sender, DetailsViewInsertEventArgs e)
                string CCIds = GetCheckBoxValues("CCIds");
                if (CCIds != null)
                    e.Values["CCIds"] = CCIds;

    Now how can I get the comma separated values and bound them with the combobox so that it should check only those items.
  2. Hristo Valyavicharski
    Hristo Valyavicharski avatar
    975 posts

    Posted 26 Nov 2014 Link to this post


    This post is duplicated to:


    Hristo Valyavicharski

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

Back to Top