check all items on page load

6 posts, 1 answers
  1. Aarsh
    Aarsh avatar
    192 posts
    Member since:
    Jun 2012

    Posted 26 Feb 2013 Link to this post

    Hello,

    At the moment I am using this LINQ query in C# to check all items but I am wanting to do the same in javascript.

    void cblMagistrateCourts_Load(object sender, EventArgs e)
    {
        RadComboBox c = (RadComboBox)sender;
        IEnumerable<RadComboBoxItem> uncheckedItems =
                                         from uncheckedItem in c.Items.ToList()
                                         where uncheckedItem.Checked == false
                                         select uncheckedItem;
        foreach (RadComboBoxItem i in uncheckedItems)
        {
            i.Checked = true;
        }
    }

    I tried the following 3 thigns in javascript and in IE F12 tools I tried to find & 'check' the 'Check All' to but that did not seemed to be checking all items (Not sure)

    not sure the 2nd attempt was in the right direction. I am getting the correct id of radCombobox using sender.get_id();

    function radCblCheckAll(sender, eventArgs) {
        //var combo = sender.get_id();
        //var chkAll = combo + '_Header_SelectAll';
        //alert(chkAll.toString());
        //chkAll.checked = true;
     
        //alert($telerik.$('.rcbCheckAllItemsCheckBox').checked);
        //$telerik.$('.rcbCheckAllItemsCheckBox').change(function () {
        //    if (sender.get_text() == "All items checked") {
        //        sender.checked = true;
        //    }
        //});
     
        var combo = sender.get_id();
        var item = combo.findItemByText('Check All');
        item.select();
     
    }
  2. Answer
    Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 26 Feb 2013 Link to this post

    Hello Aarsh,

    Try the following JavaScript to check all the items in the RadComboBox on client side page load.

    JavaScript:
    <script type="text/javascript">
        function pageLoad() {
            var combobox = $find('<%=RadComboBox1.ClientID %>');
            var items = combobox.get_items();
            var itemCount = items.get_count()
            for (var counter = 0; counter < itemCount; counter++) {
                var item = items.getItem(counter);
                item.set_checked(true)
            }
        }
    </script>

    Thanks,
    Shinu.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Ben
    Ben avatar
    31 posts
    Member since:
    Feb 2013

    Posted 27 Feb 2013 Link to this post

    Hello Shinu,

    Please help me. How to check a particular item in the Radcombobox on client pageLoad?

    Thanks,
    Ben
  5. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 28 Feb 2013 Link to this post

    Hello,

    Please try the following JavaScript to check a particular item in the RadComboBox on client side page load.

    JavaScript:
    <script type="text/javascript">
        function pageLoad() {
            var combo = $find("<%= RadComboBox1.ClientID %>");
            var item = combo.findItemByText("Your Item Text");
            item.set_checked(true);
        }
    </script>

    Thanks,
    Shinu.
  6. Aarsh
    Aarsh avatar
    192 posts
    Member since:
    Jun 2012

    Posted 23 Apr 2013 Link to this post

    The suggested approach (2nd post in this thread) did worked, but there is a problem. If I use this function on  $(document).ready() the object is undefined. And alternatively if I use it on ClientLoad client side event handler, it does the job but a function I am calling during page load un-certainly gives 0 for ddCategories.CheckedItems count and does not iterate in turn :-(

    Any suggestions ?
  7. Boyan Dimitrov
    Admin
    Boyan Dimitrov avatar
    1746 posts

    Posted 26 Apr 2013 Link to this post

    Hello,

    The document ready state is a little bit early in the page life cycle and the client objects are not yet initialized. Therefore the safest way would be to use the pageLoad event when the RadComboBox client-side object is initialized and ready to be accessed and used.

    Regards,
    Boyan Dimitrov
    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
UI for ASP.NET Ajax is Ready for VS 2017