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

Maximum Checked Items

2 Answers 404 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Nick
Top achievements
Rank 1
Nick asked on 27 Dec 2011, 09:05 AM
Hi, I was wondering how you set the maximum number of selections a user can make when the ComboBox is set to checkboxes="True" ? 

Thanks in advance.

2 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 27 Dec 2011, 11:23 AM
Hello,

Try the following javascript.
JS:
<script type="text/javascript">
 function OnClientItemChecking(sender, args)
  {
    if (sender.get_checkedItems().length == 5)
   {
     alert("count exceeded");
     args.set_cancel(true);
   }
 }
</script>

Thanks,
Princy.
0
Ivana
Telerik team
answered on 27 Dec 2011, 11:50 AM
Hi Nick,

There is no built-in functionality, which controls the number of checked items, in the RadComboBox. This, however, could be easily implemented using the client-side API of the control.
Here is an example showing how it could be achieved:

function clientItemChecking(sender, args)
{
    var checkedItems = sender.get_checkedItems().length;
    if (checkedItems >= 2 && (args.get_item().get_checked() == false))
    {
        args.set_cancel(true);
    }
}
<telerik:RadComboBox runat="server" ID="RadComboBox1" CheckBoxes="true" OnClientItemChecking="clientItemChecking">
    <Items>
        <telerik:RadComboBoxItem Text="Berlin" Value="Berlin" />
        <telerik:RadComboBoxItem Text="Paris" Value="Paris" />
        <telerik:RadComboBoxItem Text="Rome" Value="Rome" />
        <telerik:RadComboBoxItem Text="London" Value="London" />
    </Items>
</telerik:RadComboBox>

I hope this helps.

Kind regards,
Ivana
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
Tags
ComboBox
Asked by
Nick
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Ivana
Telerik team
Share this question
or