How to disable and hide a single checkbox?

4 posts, 0 answers
  1. Jeremy
    Jeremy avatar
    14 posts
    Member since:
    Mar 2012

    Posted 13 Mar 2012 Link to this post

    I am receiving a dictionary which I am binding to the combobox control. I wrote a loop that iterates through the items collection and changes some flagged items to a separator item. The problem is, if checkboxes are enabled, the seperator also receives a checkbox which sort of defeats the functionality. Is there something I could add to my loop that will disable the checkbox on these items?

    Here is an example of the code that I'm using to create the seperators:

    public static void FormatList(ref RadComboBox assignees)
    {
        for (int i = 0; i < assignees.Items.Count; i++)
        {
            if (assignees.Items[i].Text == "people")
            {
                assignees.Items[i] = new Telerik.Web.UI.RadComboBoxItem("Assign to Person:");
                assignees.Items[i].IsSeparator = true;                   
            }
            if (assignees.Items[i].Text == "group")
            {
                assignees.Items[i] = new Telerik.Web.UI.RadComboBoxItem("Assign to Group:");
                assignees.Items[i].IsSeparator = true;
            }
        }
    }

  2. Kevin
    Kevin avatar
    360 posts
    Member since:
    Jul 2012

    Posted 14 Mar 2012 Link to this post

    Hello Jeremy,

    That looks like a strange bug that should be fixed by Telerik, but for the time being you could add a css class to your page and add it to your separator items so it hides the checkbox.

    .hideGroupCheckBox .rcbCheckBox
    {
        display: none;
    }

    I hope that helps.

  3. Jeremy
    Jeremy avatar
    14 posts
    Member since:
    Mar 2012

    Posted 15 Mar 2012 Link to this post

    Thanks, that seems like it would work. But would that still work if I'm not using an ItemTemplate? In the meanwhile, I went in and took care of it with some javascript:

    <script type="text/javascript">
            function OnClientDropDownOpening(sender, eventArgs) {
                var items = sender.get_items(); for (i = 0; i < items.get_count(); i++) {
                    if (items.getItem(i).get_isSeparator()) {
                        var checkbox = items.getItem(i).get_checkBoxElement();
                        checkbox.style.display = "none";
                    }
                }
            }
     </script>


    Then added it to the dropdown event:

    <rad:RadComboBox runat="server" ID="cboAssignees" OnClientDropDownOpening="OnClientDropDownOpening" />

  4. Kalina
    Admin
    Kalina avatar
    918 posts
    Member since:
    Dec 2013

    Posted 19 Mar 2012 Link to this post

    Hello Jeremy,

    You can try this style:

    <style type="text/css">   
        .rcbSeparator input { display: none }
    </style>

    All the best,
    Kalina
    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.

Back to Top