This is asp.net article shows how to
Check/Uncheck select/deselect all child checkboxes of a table or
gridview or datagrid as header checkbox Check/Uncheck select/deselect
in asp.net through JavaScript.
function SelectAllCheckboxes(Chk) {
var IsChecked = Chk.checked;
var Chk = Chk;
var Parent = document.getElementById('gvUsers');
var items = Parent.getElementsByTagName('input');
for (i = 0; i < items.length; i++) {
if (items[i].id != Chk && items[i].type == "checkbox") {
if (items[i].checked != IsChecked) {
items[i].click();
}
}
}
}
//Or use this if your checkboxes in first column of gridview/table
<asp:CheckBox ID="CheckBox1" onchange="SelectAllCheckboxes(this)" runat="server" />
function SelectAllCheckboxes(Chk) {
var IsChecked = Chk.checked;
var Chk = Chk;
var Parent = document.getElementById('gvUsers');
for (i = 0; i < Parent.rows.length; i++) {
var tr = Parent.rows[i];
//var td = tr.childNodes[0];
var td = tr.firstChild;
var item = td.firstChild;
if (item.id != Chk && item.type == "checkbox") {
if (item.checked != IsChecked) {
item.click();
}
}
}
}
No comments:
Post a Comment