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

MultiSelect RadCombobox - Display comma separated selected items

4 Answers 755 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Ninel
Top achievements
Rank 1
Ninel asked on 30 Sep 2013, 07:17 PM
I am using a radcombobox that I have populated with data from my database. I initially set it up to just display a static title. Now the users want to see the items that have been selected. For the life of me I cannot figure out how to accomplish this.

Can someone please help me?  I need it to work EXACTLY like this....MultiSelect CheckBox display . I just can't figure out how to do it.

Thanks,
Ninel

Here is my code:
<script type="text/javascript">
        function stopPropagation(e) {
            e.cancelBubble = true;
            if (e.stopPropagation) {
                e.stopPropagation();
            }
         }
  
         function RadComboBox_OnClientLoad(sender) {
             sender.get_inputDomElement().readOnly = "readonly";
         }
  </script>
  
  
<div>
 <telerik:RadComboBox runat="server" ID="rdProjectDeliverables"  Width="215px" CheckBoxes="true"
Text="Project Deliverables"  AllowCustomText="false" EnableLoadOnDemand="false"
EmptyMessage="Project Deliverables" OnClientLoad="RadComboBox_OnClientLoad"
OnClientItemChecked="OnClientItemChecked" AutoPostBack="true"    >
     <Items>
           <telerik:RadComboBoxItem Text="" Value="" />
            <telerik:RadComboBoxItem Text="" Value=""/>
     </Items>
     <ItemTemplate>
        <asp:CheckBox runat="server" ID="CheckBox" onclick="stopPropagation(event);" oncheckedchanged="rdProjectDeliverables_CheckedChanged"   AutoPostBack= "true" Text=""/> <%# DataBinder.Eval(Container, "Text") %>
     </ItemTemplate>
   </telerik:RadComboBox>
</div>


protected void rdProjectDeliverables_CheckedChanged(object sender, EventArgs e)
    {
        GetMultiSelectDropDownSelections(rdProjectDeliverables);
    }

private void GetMultiSelectDropDownSelections(RadComboBox ddl)
{
    ArrayList checkedItems = GetCheckedItems(ddl);
    foreach (RadComboBoxItem item in checkedItems)
    {
        //lblMessage.Text = lblMessage.Text + item.Value + "<br>";
        if (item.Value == "9") //Value of 9 is the value of "Other" which requires a textbox to appear
        {
            pnlProjectDeliverablesOther.Visible = true;
            requestitem.ProjectDeliverablesOther = fldProjectDeliverablesOther.Text;
        }
        requestitem.RequestId = _requestid;
        requestitem.Value = DataHelper.ToInt32(item.Value);
         if (_requestorid > 0)
        {
            requestitem.MultiSelectionSave();
        }
    }
}
private ArrayList GetCheckedItems(RadComboBox ddl)
{
    ArrayList checkedItems = new ArrayList();
    foreach (RadComboBoxItem item in ddl.Items)
    {
        CheckBox checkBox = (CheckBox)item.FindControl("CheckBox");
        if (checkBox.Checked)
        {
            checkedItems.Add(item);
        }
    }
    return checkedItems;
}

4 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 01 Oct 2013, 03:58 AM
Hi Ninel,

I assume that you need to display the selected items of a RadComboBox. Below is a sample code that I tried. If it doesn't help please elaborate your requirement.

ASPX:
<telerik:RadComboBox ID="RadComboBox1" runat="server" Height="200px" Width="250px"
            DataSourceID="SqlDataSource1" DataTextField="ProductName" DataValueField="ProductID"
            AutoPostBack="true" CheckBoxes="true">
</telerik:RadComboBox>
        <asp:SqlDataSource runat="server" ID="SqlDataSource1" ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
            ProviderName="System.Data.SqlClient" SelectCommand="SELECT [ProductID], [ProductName] FROM [Products] ORDER By ProductName">
</asp:SqlDataSource>
<telerik:RadButton ID="RadButton1" runat="server" Text="GetItems" OnClick="RadButton1_Click"
</telerik:RadButton>
<asp:Label ID="SelectedItem1" runat="server">
</asp:Label>

C#:
protected void rdProjectDeliverables_CheckedChanged(object sender, EventArgs e)
{
    GetMultiSelectDropDownSelections(RadComboBox1);
}
protected void RadButton1_Click(object sender, EventArgs e)
{
    GetMultiSelectDropDownSelections(RadComboBox1);
}
private void GetMultiSelectDropDownSelections(RadComboBox ddl)
{      
    var SelectedItem = new StringBuilder();
    foreach (RadComboBoxItem item in RadComboBox1.CheckedItems)
    {  
        SelectedItem.Append("<li>" + item.Text + "</li>");
        SelectedItem1.Text = SelectedItem.ToString();
        if (item.Text == "")
        {
            //your code
        }
    }
}

Thanks,
Princy.
0
Ninel
Top achievements
Rank 1
answered on 01 Oct 2013, 12:51 PM
Hi Princy,
Thanks for the quick response. This is half of what I need. I need the user's selections to appear as they are selecting the checkboxes, not after they click on a button to view their selections. Can this be accomplished?

Thanks,
Ninel
0
Ninel
Top achievements
Rank 1
answered on 01 Oct 2013, 02:04 PM
I think I figured it out. Thanks again Princy.
0
Fawad
Top achievements
Rank 1
answered on 21 Nov 2014, 11:01 AM
Hi Ninel,
Can you please let me know how you did it?
Tags
ComboBox
Asked by
Ninel
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Ninel
Top achievements
Rank 1
Fawad
Top achievements
Rank 1
Share this question
or