to select all check boxes in a gridview using javascript
<script type="text/javascript" language="javascript">
function SelectAll(id) {
var grid = document.getElementById("<%= gv.ClientID %>");
var cell;
if (grid.rows.length > 0) {
for (i = 1; i < gv.rows.length; i++) {
cell = grid.rows[i].cells[0];
for (j = 0; j < cell.childNodes.length; j++) {
if (cell.childNodes[j].type == "checkbox") {
cell.childNodes[j].checked = id.checked;
}
}
}
}
}
</script>
Usage :
<asp:CheckBox ID="ChkAll" runat="server" onclick="javascript:SelectAll(this);" />
<script type="text/javascript" language="javascript">
function SelectAll(id) {
var grid = document.getElementById("<%= gv.ClientID %>");
var cell;
if (grid.rows.length > 0) {
for (i = 1; i < gv.rows.length; i++) {
cell = grid.rows[i].cells[0];
for (j = 0; j < cell.childNodes.length; j++) {
if (cell.childNodes[j].type == "checkbox") {
cell.childNodes[j].checked = id.checked;
}
}
}
}
}
</script>
Usage :
<asp:CheckBox ID="ChkAll" runat="server" onclick="javascript:SelectAll(this);" />
No comments:
Post a Comment