How to check the 'All' checkbox from the code behind?

Nov 14, 2012 at 2:13 PM

Hey All, I want to check all in the we have any shortcut to do it...I have thousands items in the dropdown...looping is making my page to automatically make it selected?

foreach (ListItem item in DD.Items)
item.Selected = true;


Please help me, I am using it for the company i am working for...they are asking me to improve the page is a high priority for me....

Aug 30, 2013 at 8:00 AM
Edited Aug 30, 2013 at 8:04 AM

Maybe too late for answering this question, but I've got a solution (i think) for my project few hours ago.

I did it through javascript, investigating the source code of the control, with the following code:

function dropdownCheckBoxesSelectAll(dropdownID) {
/* Select all the phyisical checkbox of the control */
var i = 0;
this.checkBox = document.getElementById("MainContent_" + dropdownID + "_" + i);
while (this.checkBox != null) {
    this.checkBox.checked = true;
    this.checkBox = document.getElementById("MainContent_" + dropdownID + "_" + i);

/* Select the virtual "SelectAll" checkbox of the control */
$("#" + "MainContent_" + dropdownID + "_dv" + " input[type='checkbox']:first").attr("checked", true);

"MainContent_dropDownID_dv" is the way to access the "div" wich contains the virtual "SelectAll" node. Maybe, the "MainContent" expression is different in each project.

And then, in the code behind:
ClientScript.RegisterStartupScript(GetType(), "dropdownCheckBoxesSelectAll", "dropdownCheckBoxesSelectAll('" + dropDownControl.ID + "');", true);
Where "dropDownControl" is the variable in the code behind wich identifies the control.

If someone finds some correction to do in this code, please, do not hesitate to answer this post. Thanks.