Click here to Skip to main content
16,020,298 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
JavaScript
$(function () {
         debugger;
         //Enable Disable all TextBoxes when Header Row CheckBox is checked.
         $("[id*=chkHeader]").bind("click", function () {
             var chkHeader = $(this);
             alert("hi")
             //Find and reference the GridView.
             var grid = $(this).closest("table");

             //Loop through the CheckBoxes in each Row.
             $("td", grid).find("input[type=checkbox]").each(function () {

                 //If Header CheckBox is checked.
                 //Then check all CheckBoxes and enable the TextBoxes.
                 if (chkHeader.is(":checked")) {
                     $(this).attr("checked", "checked");
                     var td = $("td", $(this).closest("tr"));
                     td.css({ "background-color": "#D8EBF2" });
                     $("input[type=text]", td).removeAttr("disabled");
                 } else {
                     $(this).removeAttr("checked");
                     var td = $("td", $(this).closest("tr"));
                     td.css({ "background-color": "#FFF" });
                     $("input[type=text]", td).attr("disabled", "disabled");
                 }
             });
         });

         //Enable Disable TextBoxes in a Row when the Row CheckBox is checked.
         $("[id*=chkRow]").bind("click", function () {

             //Find and reference the GridView.
             var grid = $(this).closest("table");

             //Find and reference the Header CheckBox.
             var chkHeader = $("[id*=chkHeader]", grid);

             //If the CheckBox is Checked then enable the TextBoxes in thr Row.
             if (!$(this).is(":checked")) {
                 var td = $("td", $(this).closest("tr"));
                 td.css({ "background-color": "#FFF" });
                 $("input[type=text]", td).attr("disabled", "disabled");
             } else {
                 var td = $("td", $(this).closest("tr"));
                 td.css({ "background-color": "#D8EBF2" });
                 $("input[type=text]", td).removeAttr("disabled");
             }

             //Enable Header Row CheckBox if all the Row CheckBoxes are checked and vice versa.
             if ($("[id*=chkRow]", grid).length == $("[id*=chkRow]:checked", grid).length) {
                 chkHeader.attr("checked", "checked");
             } else {
                 chkHeader.removeAttr("checked");
             }
         });
     });


What I have tried:

please rectify this code to work in panel
Posted
Updated 27-Jul-17 2:34am
v2
Comments
Graeme_Grant 27-Jul-17 6:11am    
"please rectify" - this is not our problem but yours. Ask for any help, please don't demand!

What is happening? What have you used to debug your code? Have you searched Google for answers?

For a better understanding of how Q&A works and the proper etiquette, please read the Code Project Quick Answers FAQ[^]

1 solution

if you are using update panel the jquery's document ready function will not work as expected,
replace
$(function () {
// your code
});

with pageLoad function

function pageLoad(){
 // your   code..
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900