Hello All,
I am unable to work my Jquery code for checking all the checkboxes which is inserted in a GridView Usercontrol.However,The same code works perfectly fine when I change the user control to a web form.
ie,from .ascx to .aspx.
Please Advice.
Thanks,
NeelSan
Below is my Code :
Default.ascx : <%@ Control Language="C#" AutoEventWireup="true" CodeBehind="Default.ascx.cs" Inherits="ViewGrid._Default" %>
<div>
<table>
<tr>
<td>
<asp:GridView ID="grdView" runat="server" AutoGenerateColumns="false">
<HeaderStyle Height="20px" HorizontalAlign="Center" />
<RowStyle Height="18px" />
<AlternatingRowStyle Height="18px" />
<Columns>
<asp:TemplateField>
<HeaderTemplate>
<asp:CheckBox ID="chkAll" runat="server" />
</HeaderTemplate>
<ItemTemplate>
<asp:CheckBox ID="chkSelect" runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField Visible="false">
<ItemTemplate>
<asp:Label ID="lblP2PId" runat="server" Text='<%Eval("p2pid") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="productname" HeaderText="Productname" SortExpression="Productname" >
<HeaderStyle CssClass="" />
<ItemStyle CssClass="" />
</asp:BoundField>
<asp:BoundField DataField="UnitPrice" HeaderText="UnitPrice" SortExpression="UnitPrice">
<HeaderStyle CssClass="" />
<ItemStyle CssClass="" />
</asp:BoundField>
<asp:BoundField DataField="Number" HeaderText="Number" SortExpression="Number">
<HeaderStyle CssClass="" />
<ItemStyle CssClass="" />
</asp:BoundField>
</Columns>
</asp:GridView>
</td>
</tr>
<tr>
<td>
</td>
</tr>
</table>
</div>
<script type='text/javascript' src='Jquery.js'></script>
<script type="text/javascript">
$(document).ready(function() {
var chkBox = $("input[id$='chkAll']");
chkBox.click(
function() {
$("#grdView INPUT[type='checkbox']")
.attr('checked', chkBox
.is(':checked'));
});
// To deselect CheckAll when a GridView CheckBox
// is unchecked
$("#grdView INPUT[type='checkbox']").click(
function(e) {
if (!$(this)[0].checked) {
chkBox.attr("checked", false);
}
});
});
</script>
Please Advice.
PS : This code works perfectly if i change from a user control back to web form
Thanks....