function CheckAllDataGridCheckBoxes(aspCheckBoxID, checkVal) { re = new RegExp(':' + aspCheckBoxID + '$') //generated control name starts with a colon for(i = 0; i < document.forms[0].elements.length; i++) { elm = document.forms[0].elements[i] if (elm.type == 'checkbox') { if (re.test(elm.name)) { elm.checked = checkVal } } } }

 

this is how you use it

INPUT id="chkSelectAll" onclick="CheckAllDataGridCheckBoxes('chkPerBooking', ProduceBookingControl1_chkSelectAll.checked)" type="checkbox" value="Select All" name="chkSelectAll" runat="server"