title: Asp.net multiple gridviews, checkboxes in headertemplate select all / deselect all functionality
body: <p>I am using two gridview controls in my aspx page. And I have a column of checkbox in both my controls. I am facilitating the user to select/deselect all checkboxes in my both gridviews by providing a checkbox in the header template of both gridviews and using java script functions. below is the code </p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
      function UncheckParent(obj) {
          var isUnchecked = obj.checked;
          if (isUnchecked == false) {
              var frm = document.forms[0];
              for (i = 0; i &lt; frm.length; i++) {
                  if (frm.elements[i].id.indexOf('chkSelectAllCheckboxes') != -1) {
                      frm.elements[i].checked = false;
                  }
              }
          }
  
      }
  
      function CheckAll(obj) {
          var row = obj.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode;
          var inputs = row.getElementsByTagName("input");
          for (var i = 0; i &lt; inputs.length; i++) {
              if (inputs[i].type == "checkbox") {
                  inputs[i].checked = obj.checked;
              }
          }
      }
  &lt;/script&gt;
  </code></pre>
  
  <p>But the problem is that once i select or deselect one of such checkboxes all checkboxes in both the gridviews get checked. I can also give a short example of what is happening. Two gridviews gdvwStudents and gdvwTeachers. Both have checkbox column and a check box in header template. using above code when I click header checkbox of gdvwStudents, all checkboxes in gdvStudents and gdvTeachers get selected. Please  </p>