Wednesday, November 11, 2009

Gridview Header CheckBox click selects all the item CheckBoxes

Below is the JavaScript function which is responsible to Select or Deselect all the CheckBoxes when Header CheckBox is clicked....
HeaderCheck(CheckBox)
{
cnt=0;
var TargetBaseControl = document.getElementById('ctl00_ContentPlaceHolder1_GridView1');
var TargetChildControl = 'ChkSel';
var Inputs = TargetBaseControl.getElementsByTagName('input');
for(var n = 0; n < type ="=">= 0)
{
Inputs[n].checked = CheckBox.checked;
}
}

Call this function in GridView's Header CheckBox onclick............Below is the code snippet
asp:templatefield
headertemplate
asp:templatefield
headertemplate
asp:checkbox id="ChkHeader" runat="server" onclick="return HeaderCheck(this);"
asp:checkbox
itemtemplate
asp:checkbox id="ChkSel" runat="server"
asp:checkbox
itemtemplate
headertemplate asp:templatefield
asp:checkbox id="ChkHeader" runat="server" onclick="return HeaderCheck(this);"
asp:checkbox
itemtemplate
asp:checkbox id="ChkSel" runat="server"
asp:checkbox
itemtemplate
headertemplate asp:templatefield

No comments:

Post a Comment