I was trying to write a code to Check / Uncheck All checkboxes in Listview with checkbox on header using JQuery.
This is the first version of my code.
$("#<%=listviewName.ClientID %>
table tbody tr th:last input:checkbox").live('click', function () {
var checkedStatus = this.checked;
$("#<%=listviewName.ClientID %>
table tbody tr td:last-child input:checkbox").each(function () {
this.checked = checkedStatus;
});
});
This is the second version of my code.
$(document).ready(function () { $('#<%=listviewName.ClientID%>
input[id*="chkselectAll"]:checkbox').live('click', function () {
$('#<%=listviewName.ClientID%>
input[id*="chkselect"]:checkbox').attr('checked', this.checked);
});
});
I finally end up with this version.
$("[id$='chkSelectAll']").live('click', function () {
$("[id$='chkSelect']").attr('checked', this.checked);
});
Note: just make sure to set clientmode to Static in the checkbox.
<asp:CheckBox ID="chkSelectAll" ClientIDMode="Static"
EnableViewState="false" runat="server" />
Just wondering how many lines of code needed to write the same in JavaScript? By the way, Any one got better version?