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

check all items on page load

5 Answers 394 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Aarsh
Top achievements
Rank 1
Aarsh asked on 26 Feb 2013, 11:09 PM

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();
 
}

5 Answers, 1 is accepted

Sort by
0
Accepted
Shinu
Top achievements
Rank 2
answered on 27 Feb 2013, 04:39 AM
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.
0
Ben
Top achievements
Rank 1
answered on 27 Feb 2013, 03:37 PM
Hello Shinu,

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

Thanks,
Ben
0
Shinu
Top achievements
Rank 2
answered on 28 Feb 2013, 06:05 AM
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.
0
Aarsh
Top achievements
Rank 1
answered on 24 Apr 2013, 12:51 AM
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 ?
0
Boyan Dimitrov
Telerik team
answered on 26 Apr 2013, 11:43 AM
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.
Tags
ComboBox
Asked by
Aarsh
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Ben
Top achievements
Rank 1
Aarsh
Top achievements
Rank 1
Boyan Dimitrov
Telerik team
Share this question
or