<asp:CheckBox ID="chkAll" Text="Select All" runat="server" />
<asp:CheckBoxList ID="chkFruits" runat="server">
<asp:ListItem Text="Mango" />
<asp:ListItem Text="Apple" />
<asp:ListItem Text="Banana" />
<asp:ListItem Text="Pineapple" />
<asp:ListItem Text="Guava" />
<asp:ListItem Text="Grapes" />
<asp:ListItem Text="Papaya" />
</asp:CheckBoxList>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript">
$(function () {
$("[id*=chkAll]").bind("click", function () {
if ($(this).is(":checked")) {
$("[id*=chkFruits] input").attr("checked", "checked");
} else {
$("[id*=chkFruits] input").removeAttr("checked");
}
});
$("[id*=chkFruits] input").bind("click", function () {
if ($("[id*=chkFruits] input:checked").length == $("[id*=chkFruits] input").length) {
$("[id*=chkAll]").attr("checked", "checked");
} else {
$("[id*=chkAll]").removeAttr("checked");
}
});
});
</script>
Reference:
No comments:
Post a Comment