Java Script for All check at Check Box
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript">
$("[id*=chkAllUser]").live("click", function () {
var chkAllUser = $(this);
var grid = $(this).closest("table");
$("input[type=checkbox]", grid).each(function () {
if (chkAllUser.is(":checked")) {
$(this).attr("checked", "checked");
$("td", $(this).closest("tr")).addClass("selected");
} else {
$(this).removeAttr("checked");
$("td", $(this).closest("tr")).removeClass("selected");
}
});
});
$("[id*=chkBox]").live("click", function () {
var grid = $(this).closest("table");
var chkAllUser = $("[id*=chkAllUser]", grid);
if (!$(this).is(":checked")) {
$("td", $(this).closest("tr")).removeClass("selected");
chkAllUser.removeAttr("checked");
} else {
$("td", $(this).closest("tr")).addClass("selected");
if ($("[id*=chkBox]", grid).length == $("[id*=chkBox]:checked", grid).length) {
chkAllUser.attr("checked", "checked");
}
}
});
</script>
ASP.Net Code
<asp:TemplateField HeaderText="" ItemStyle-Width="1%" ItemStyle-CssClass="col-center">
<%--<HeaderTemplate>
<asp:CheckBox ID="chkAllUser" runat="server" />
</HeaderTemplate>--%>
<ItemTemplate>
<asp:CheckBox ID="chkBox" runat="server" />
<input type="hidden" name="hdnUserId" id="hdnUserId" value="" />
</ItemTemplate>
<ItemStyle Width="1%"></ItemStyle>
</asp:TemplateField>
No comments:
Post a Comment