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