client side setting checkbox on client side

6 posts, 0 answers
  1. Craig
    Craig avatar
    5 posts
    Member since:
    May 2012

    Posted 23 May 2012 Link to this post

    How do I check or uncheck a checkbox in the RadComboBox when it's checkbox is allowed?
  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 24 May 2012 Link to this post

    Hi Craig,

    Try the following javascript to check or uncheck a checkbox in a RadComboBox.

    JS:
    <script type="text/javascript" >
     function OnClientClick()
      {
            var combo = $find("<%=RadComboBox1.ClientID %>");
            if (combo.get_items().getItem(0).get_checked())
            {
                combo.get_items().getItem(0).set_checked(false);
            }
            else
            {
                combo.get_items().getItem(0).set_checked(true);
            }
      }
    </script>

    Hope this helps.

    Thanks,
    Princy.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Craig
    Craig avatar
    5 posts
    Member since:
    May 2012

    Posted 24 May 2012 Link to this post

    This is very helpful thank you. Since I can't get the telerik intellisense to work it is hard to apply this where I want to. A little background will help. I have a class that generates a list of items that I want to display in a radcombobox. I can get the list to display and by enabling the checkbox feature of the combobox the user will be able select one of more items from the combobox. The problem i am trying to solve is how to make sure the first item "All" is unchecked when a user checks an item that is not "All". But also if the user does check "All" then I want to uncheck all of the other items. Since I am not familiar with the clientside API and intellisense for the telerik components is not working for clientside code I am not able to work this out on my own. Is there written documentation explaining the whole clientside API? What I have been able to find is not extensive enough.


    Craig
  5. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 25 May 2012 Link to this post

    Hi Craig,

    Here is the sample code which I tried based on your scenario. You can use debugger in IE for javascript intellisense.

    JavaScript:
    <script type="text/javascript">
     function OnClientItemChecking(sender, eventArgs)
      {
            if (eventArgs._item._properties._data.value == "all")
            {
                for (var i = 1; i < sender.get_items().get_count(); i++)
                 {
                    sender.get_items().getItem(i).set_checked(false);
                 }
            }
            else if (sender.get_items().getItem(0).get_checked())
            {
                eventArgs.set_cancel(true);
            }
      }
    </script>

    Thanks,
    Princy.
  6. SUBBU
    SUBBU avatar
    10 posts
    Member since:
    Apr 2012

    Posted 10 Feb Link to this post

    In my case, set_checked(true) alone didn't work,

        combo.get_items().getItem(0).set_checked(true);

        $(combo.get_items().getItem(0)._element).find('input').prop('checked', true);

     

    This worked for me!!!

  7. Nencho
    Admin
    Nencho avatar
    1457 posts

    Posted 15 Feb Link to this post

    Hello Subramanian,

    The demonstrated usage should properly work as it is a part of the Client API of the control.
    combo.get_items().getItem(0).set_checked(true);
    Here you can find the entire ClientAPI of the control listed with explanations and some examples:
    http://docs.telerik.com/devtools/aspnet-ajax/controls/combobox/client-side-programming/objects/radcomboboxitem-object

    In the attachment you can find a simple example, demonstrating the proper behavior of the above implementation.

    The reason why it may not work at your end is if there is any javascript error on the page. Please make sure that this is not the case.

    Regards,
    Nencho
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017