MultiSelect RadCombobox - Display comma separated selected items

5 posts, 0 answers
  1. Ninel
    Ninel avatar
    3 posts
    Member since:
    Sep 2010

    Posted 30 Sep 2013 Link to this post

    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;
    }
  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 30 Sep 2013 Link to this post

    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Ninel
    Ninel avatar
    3 posts
    Member since:
    Sep 2010

    Posted 01 Oct 2013 Link to this post

    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
  5. Ninel
    Ninel avatar
    3 posts
    Member since:
    Sep 2010

    Posted 01 Oct 2013 Link to this post

    I think I figured it out. Thanks again Princy.
  6. Fawad
    Fawad avatar
    20 posts
    Member since:
    Nov 2014

    Posted 21 Nov 2014 in reply to Ninel Link to this post

    Hi Ninel,
    Can you please let me know how you did it?
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017