I have a one grid-view with checkboxes here my requirement is if I select header checkbox of gridview I need to select all the child checkboxes in grid-view and if I deselect header checkbox I need to deselect all the child checkboxes in gridview and if I select all the child checkbox I need to select the header checkbox and if any child checkbox deselected I need to deselect header checkbox for this I have written Jquery function to achieve this functionality.
//Header Checkbox Click
$('[id$=chkHeader]').live("click", function () {
$("[id$='chkChild']").attr('checked', this.checked);
});
//Checking all the child checkboxes or checked or not if not un check the header checkbox
$("[id$='chkChild']").live("click", function () {
$("[id$='chkChild']").each(function () {
var CheckedChilds = $("[id$='chkChild']:checked").length;
var TotalChilds = $("[id$='chkChild']").length;
if (CheckedChilds == TotalChilds)
if (!$('[id$=chkHeader]').attr("checked"))
$('[id$=chkHeader]').attr("checked", "checked");
if (CheckedChilds != TotalChilds)
if ($('[id$=chkHeader]').attr("checked"))
$('[id$=chkHeader]').removeAttr("checked")
});
});
No comments:
Post a Comment