user3682373 user3682373 - 2 months ago 10x
jQuery Question

Check all checkboxes in first column of gridview?

I have done the following code to check all checkboxes in first column of gridview but it works only for IE 5.0 to 8.0 and gives a Javascript error when i run it in IE 9 and above as "Function Expected". Can anyone guide me through this ?

function selectAllItems(gridID, hdnSelectedValuesID, pagedGrid, chkSelectAllCtrl) {

var hdnSelectedValuesID = document.getElementById(hdnSelectedValuesID);
if (chkSelectAllCtrl != null) {
hdnSelectedValuesID.value = '';
var rowLength = document.getElementById(gridID).rows.length;
var upperLimitOnRows = 0;
var elementA = '';

if (pagedGrid)
upperLimitOnRows = rowLength - 1;
upperLimitOnRows = rowLength;

//Set the other checkboxes in the item section to selected
for (var Count = 1; Count < upperLimitOnRows; Count++) {
//Check all checkboxes in the first column of grid
document.getElementById(gridID).rows(Count).cells(0).childNodes(0).checked = chkSelectAllCtrl.checked; // Error In this Line


You should use square brackets instead of parentheses:

var grid = document.getElementById(gridID);
for (var count = 1; count < upperLimitOnRows; count++) {
   grid.rows[count].cells[0].childNodes[0].checked = chkSelectAllCtrl.checked;

N.B. The check box may also be the child node 1 instead of 0. That is what I see with a TemplateField but it may be different for a CheckBoxField or an auto-generated column.