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

Need to check checkbox item from outside the control

2 Answers 71 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Albert
Top achievements
Rank 1
Albert asked on 18 Jan 2013, 01:23 AM
I have a Gridview that uses a RadComboBox with checkboxes enabled to choose an Approval code or multiple denial codes. 

I have a asp:checkbox in the grid up in the header as well as next to each RadComboBox control as an 'Approve All' function. It should work similar to the checkboxes in Gmail.
You asp:checkbox in the header, which should check each asp:checkbox next to the RadComboBox controls in each row, will also set each RadComboBox to have the Approve item checked for selection.
When you uncheck a asp:checkbox next to the RadComboBox, you only uncheck that RadComboBox, not all controls in all rows.

I was wanting to do this all client side but can't see the get the checkboxes in the RadComboBox to check or uncheck. Also, I don't know if they are checked clientside if they will be picked up serverside when I'm ready to submit the approvals.

The code is something like what follows:
UPDATED THE CODE - When I had typed this out, I was writing it from memory. I have now posted the code as I am using it. The alerts do come up when I check or uncheck the checkbox next to the RadComboBox.

$(checkBoxSelector).live('click', function () {
                var index = $(checkBoxSelector).index(this);
                var gridRow = $('#MainContent_QueueGrid > tbody > tr:eq(' + index + ')');
 
                if ($(this).is(":checked")) {
                    gridRow.find('.rcbCheckBox').each(function () {
                        if ($(this)[0].nextSibling.wholeText === 'Approve') {
                            $(this)[0].attr("checked", true);
                            alert("Checking the box");
                        }
                    });
                }
                else {
                    gridRow.find('.rcbCheckBox').each(function () {
                        if ($(this)[0].nextSibling.wholeText === 'Approve') {
                            $(this)[0].attr("checked", false);
                            alert("UNChecking the box");
                        }
                    });
                }
            });

I have tried every which way to check or uncheck the Approval code inside the RadComboBox and it is not working.
I can see the Approval checkbox element when I get to the if statement but am not able to set the attribute to checked.
I have tried attr('checked', true) along with every other way I can find.

I know that if the asp:checkboxes are selected I could evaluate the grid with those, but my issue is for user experience. If the Approve All is selected, all of the RadComboBoxes should show Approved as the selcted text as well as if they open the RadComboBox, they should we Approved checked and possibly all denial codes disabled.

Is this something that can be done?
With your help, if I am successful in setting it, will the checked status hold when evaluating the grid in code behind?


Any help is greatly appreciated.
Thanks in advance.


2 Answers, 1 is accepted

Sort by
0
MasterChiefMasterChef
Top achievements
Rank 2
answered on 18 Jan 2013, 04:59 PM
{ deleted }
0
Angel Petrov
Telerik team
answered on 22 Jan 2013, 04:15 PM
Hi Albert,

You can attach an event handler which according to the check box state checks the item in the RadComboBox. This is demonstrated in the code snippet below:

JavaScript:
$telerik.$('#CheckBox1').change(function () {
                    var checkedState = $telerik.$('#CheckBox1').attr("checked");
                    var combo = $find("<%= RadComboBox1.ClientID %>");
                    var currentItem = combo.findItemByText("Approve");
                    if (checkedState) {
                        currentItem.set_checked(true);
                    }
                    else {
                        currentItem.set_checked(false);
                    }
                     
                });

In attachments you can find a sample solution demonstrating the upper-mentioned approach. Note that the changes made client-side are persisted server-side.

All the best,
Angel Petrov
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
Albert
Top achievements
Rank 1
Answers by
MasterChiefMasterChef
Top achievements
Rank 2
Angel Petrov
Telerik team
Share this question
or