Telerik Radcombobox multiple selections with Checkboxes Server Side

by pencilvac 3/13/2012 12:09:00 PM

The Telerik Radcombobox control is great for selecting single values from a drop down list, but with the new addition of the control's CheckBoxes property adding checkboxes and allowing users to make multiple selections is quite easy.

First you need a radcombobox control:

<telerik:RadComboBox ID="rcbServiceTypes"  runat="server" CheckBoxes="True" />

Something to keep in mind: Right from the Telerik Doc's:

  • MarkFirstMatch and Filter functionalities are not supported. The reason is that the CheckBox selection is different from the standard RadComboBox's selection - there is no single selected item.
  • Load On Demand functionality is not supported. The reason is that RadComboBox's items loaded on demand are not accessible on the server which is needed for the CheckBox feature

Databind the control just like you would any other dropdownlist:

 private void LoadDropDownLists()

{

           //databind the radcombobox with values from your database

            rcbServiceTypes.DataSource = Utility.GetLookups(9);
            rcbServiceTypes.DataTextField = "LU_Value";
            rcbServiceTypes.DataValueField = "ID";
            rcbServiceTypes.DataBind();

            //preselect a default values checkbox if you want

            RadComboBoxItem item1 = new RadComboBoxItem();
            item1 = rcbServiceTypes.Items.FindItemByValue("49");
            item1.Checked = true;

}

When you want to access the values that the user has checked off from the combobox in the code behind you can do something like this:

                   //create an array to store service types checked in the drop down

                    int itemschecked = rcbServiceTypes.CheckedItems.Count;      //the total boxes that were checked
                    String[] ServiceTypesArray = new String[itemschecked];        //an array to store the values

                    //now lets loop through the service types and get their value
                    var collection = rcbServiceTypes.CheckedItems;    //this variable holds all of the checked boxes so we can loop through
                    int i = 0;
                    foreach (var item in collection)
                     {

                       String value = item.Value; //grab the current check boxes value , you can also use .text to grab the text of the item selected
                       ServiceTypesArray[i] = value; //store it in the array
                       i++;
                     }
                    var ServiceTypes = String.Join(",", ServiceTypesArray); // If you need a String instead of an array then break the array into a comma separated string

Pretty easy to do.

NOTE: If you are having problems where your combobox.CheckedItems is coming up as 0 for a count but you are checking off boxes for sure then

make sure that some properties of your control on the front end are not interfering with the checkboxes property. The documentation on Telerik is not overly extensive.

Check out Teleriks documentation:

Telerik Radcombobox Checboxes Documentation

Tags: , , , ,

.NET | ASP.NET Enterprise Library | Telerik

Powered by BlogEngine.NET 1.5.0.7
Theme by Mads Kristensen

About the author

Name of author Author name
Something about me and what I do.

E-mail me Send mail

Calendar

<<  July 2017  >>
MoTuWeThFrSaSu
262728293012
3456789
10111213141516
17181920212223
24252627282930
31123456

View posts in large calendar

Recent comments

Tags

Disclaimer

The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

© Copyright 2017

Sign in