function SelectheaderItemCheckbox(checkboxall) {
if (checkboxall.checked) {
var inputs = document.getElementById(dataGrid).getElementsByTagName('input');
for (var i = 1; i < inputs.length; i++) {
if (inputs[i].type == "checkbox") {
inputs[i].checked = true;
}
}
}
else {
var inputs = document.getElementById(dataGrid).getElementsByTagName('input');
for (var i = 1; i < inputs.length; i++) {
if (inputs[i].type == "checkbox") {
inputs[i].checked = false;
}
}
}
}
function SelectchildCheckboxes(header) {
var inputs = document.getElementById(dataGrid).getElementsByTagName('input');
var countCheckboxItem = 0;
var countCheckboxSelected = 0;
for (var i = 1; i < inputs.length; i++) {
if (inputs[i].type == "checkbox") {
countCheckboxItem++;
if (inputs[i].checked) {
countCheckboxSelected++;
}
}
}
if (countCheckboxSelected == countCheckboxItem) {
inputs[0].checked = true;
}
else {
inputs[0].checked = false;
}
}
<asp:GridView ID="GridViewItems" runat="server" AutoGenerateColumns="false" DataKeyNames="ItemId"
AllowPaging="true" PageSize="10" OnRowCommand="GridViewItems_RowCommand" OnPageIndexChanging="GridViewItems_PageIndexChanging">
<Columns>
<asp:TemplateField>
<HeaderTemplate>
<div class="TblChk">
<asp:CheckBox ID="CheckBoxSelectAll" onclick="javascript:SelectheaderItemCheckbox(this)"
class="FloatLeft" runat="server" />
</div>
</HeaderTemplate>
<ItemTemplate>
<asp:CheckBox ID="CheckBoxItem" onclick="javascript:SelectchildCheckboxes(this)"
runat="server" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
<EmptyDataTemplate>
No Records Found....
</EmptyDataTemplate>
</asp:GridView>
if (checkboxall.checked) {
var inputs = document.getElementById(dataGrid).getElementsByTagName('input');
for (var i = 1; i < inputs.length; i++) {
if (inputs[i].type == "checkbox") {
inputs[i].checked = true;
}
}
}
else {
var inputs = document.getElementById(dataGrid).getElementsByTagName('input');
for (var i = 1; i < inputs.length; i++) {
if (inputs[i].type == "checkbox") {
inputs[i].checked = false;
}
}
}
}
function SelectchildCheckboxes(header) {
var inputs = document.getElementById(dataGrid).getElementsByTagName('input');
var countCheckboxItem = 0;
var countCheckboxSelected = 0;
for (var i = 1; i < inputs.length; i++) {
if (inputs[i].type == "checkbox") {
countCheckboxItem++;
if (inputs[i].checked) {
countCheckboxSelected++;
}
}
}
if (countCheckboxSelected == countCheckboxItem) {
inputs[0].checked = true;
}
else {
inputs[0].checked = false;
}
}
<asp:GridView ID="GridViewItems" runat="server" AutoGenerateColumns="false" DataKeyNames="ItemId"
AllowPaging="true" PageSize="10" OnRowCommand="GridViewItems_RowCommand" OnPageIndexChanging="GridViewItems_PageIndexChanging">
<Columns>
<asp:TemplateField>
<HeaderTemplate>
<div class="TblChk">
<asp:CheckBox ID="CheckBoxSelectAll" onclick="javascript:SelectheaderItemCheckbox(this)"
class="FloatLeft" runat="server" />
</div>
</HeaderTemplate>
<ItemTemplate>
<asp:CheckBox ID="CheckBoxItem" onclick="javascript:SelectchildCheckboxes(this)"
runat="server" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
<EmptyDataTemplate>
No Records Found....
</EmptyDataTemplate>
</asp:GridView>