I made this simple code to check all checkboxes in a gridview 
function chkFun() {
        if ($("#chkSelectAll").is(':checked')) {
            $("#grdSearchResults tr").each(function () {
                debugger
                var checkBox = $(this).find("input[id*='chkSelected']");
                $(checkBox).attr("checked", true);
            });
        }
        else {
            $("#grdSearchResults tr").each(function () {
                debugger
                var checkBox = $(this).find("input[id*='chkSelected']");
                $(checkBox).attr("checked", false);
            });
        }
    }
chkFun will called in the chkAll checkbox OnClicking.. and it is working fine in the 1st time [selecting & deselecting] .. after that it is not working at all and i don't know why.
I tried to debugg it as u see in code it go right in everywhere .. but this line $(checkBox).attr("checked", false); is not doing any thing after the first time
 
     
    