jeudi 26 février 2015

ASP.NET Checkbox won't check with jQuery

I am attempting to make my checkboxes in a GridView easier to check for the user. I have added some jQuery to make the element clickable and check the checkbox. That part works. The problem is, when the user clicks the actual checkbox it will not check. When I debug my code, it appears that the .is(":checked") is not returning correctly. Any help will be appreciated.


My GridView ItemTemplate



<asp:TemplateField HeaderText="Select" ItemStyle-Width ="5%" ItemStyle-HorizontalAlign="Center" ItemStyle-CssClass="chk" >
<ItemTemplate>
<asp:CheckBox id="chkBxPSelect" runat="server" />
</ItemTemplate>
</asp:TemplateField>


My jQuery



$(".chk").click(function (e)
{
//var checkBox = $(this).closest("td").find("input[type=checkbox]");
//var checkBox = $(this).children("input:checkbox");
var checkBox = $(this).find("input:checkbox:first");

if (checkBox.is(":checked"))
{
checkBox.prop("checked", false);
}
else
{
checkBox.prop("checked", true);
}


});


Any ideas?





Aucun commentaire:

Enregistrer un commentaire