Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. aspxgridview,checkbox and check all

aspxgridview,checkbox and check all

Scheduled Pinned Locked Moved C#
javajavascripttoolshelp
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    tomorrow_ft
    wrote on last edited by
    #1

    hi, I am using an aspxgridview and two checkboxes(for header and dataitem).When I check header checkbox I want to check all checkbox.I am also using java script code.essentially, I can do this, but I must check header checkbox twice times.I didnt understand why it is happening.ı am writing this code checkbox_checked event and header checkbox's autopostpak is true. When I used normal gridview I didnt have any problem I could do this without problem.,

    <script language="javascript" type="text/javascript">
    function SelectAll(id) {

        var IsChecked = id.checked;
        var Chk = id;
       // Parent = document.getElementById('GrdPerliste');
        Parent = document.getElementById('<% = GrdPerliste.ClientID%>');
    
        var items = Parent.getElementsByTagName('input');
        for (i = 0; i < items.length; i++) {
            var deneme = items\[i\].type;
            if (items\[i\].id != Chk && items\[i\].type == "checkbox") {
                if (items\[i\].checked != IsChecked)
                { items\[i\].click(); }
            }
        }
    
    }
        </script>
    

    protected void Checksec_CheckedChanged2(object sender, EventArgs e) { CheckBox chk = (CheckBox)sender; GridViewHeaderTemplateContainer bulundugucontainer = (GridViewHeaderTemplateContainer)chk.NamingContainer; ((CheckBox)bulundugucontainer.FindControl("Checksec")).Attributes.Add("onclick", "javascript:SelectAll('" + ((CheckBox)bulundugucontainer.FindControl("Checksec")).ClientID + "')"); }

    K 1 Reply Last reply
    0
    • T tomorrow_ft

      hi, I am using an aspxgridview and two checkboxes(for header and dataitem).When I check header checkbox I want to check all checkbox.I am also using java script code.essentially, I can do this, but I must check header checkbox twice times.I didnt understand why it is happening.ı am writing this code checkbox_checked event and header checkbox's autopostpak is true. When I used normal gridview I didnt have any problem I could do this without problem.,

      <script language="javascript" type="text/javascript">
      function SelectAll(id) {

          var IsChecked = id.checked;
          var Chk = id;
         // Parent = document.getElementById('GrdPerliste');
          Parent = document.getElementById('<% = GrdPerliste.ClientID%>');
      
          var items = Parent.getElementsByTagName('input');
          for (i = 0; i < items.length; i++) {
              var deneme = items\[i\].type;
              if (items\[i\].id != Chk && items\[i\].type == "checkbox") {
                  if (items\[i\].checked != IsChecked)
                  { items\[i\].click(); }
              }
          }
      
      }
          </script>
      

      protected void Checksec_CheckedChanged2(object sender, EventArgs e) { CheckBox chk = (CheckBox)sender; GridViewHeaderTemplateContainer bulundugucontainer = (GridViewHeaderTemplateContainer)chk.NamingContainer; ((CheckBox)bulundugucontainer.FindControl("Checksec")).Attributes.Add("onclick", "javascript:SelectAll('" + ((CheckBox)bulundugucontainer.FindControl("Checksec")).ClientID + "')"); }

      K Offline
      K Offline
      Karthik Harve
      wrote on last edited by
      #2

      try this javascript function

      //cntrl- ID of the parent Check box
      //grd - Cliend ID of the HTML Table or GridView in which all the check boxes
      // are present
      // indCat - 1 or 2 indicates call from parent or child

      function SelectAll(cntrl,grd,indCat)
      {
      var grdComp = document.getElementById(grd);

      if(indCat == '1')    
      {
          for(i=1;i<=grdComp.getElementsByTagName('input').length-1;i++)
          {
              grdComp.getElementsByTagName('input')\[i\].checked = cntrl.checked;
          }
      }
      else if(indCat == '2')
      { 
          var chkInd = true;
          for(i=1;i<=grdComp.getElementsByTagName('input').length-1;i++)
          {                 
              if(grdComp.getElementsByTagName('input')\[i\].checked == false)
              {
                  chkInd = false;
              }                    
          }
          grdComp.getElementsByTagName('input')\[0\].checked = chkInd;             
      }
      

      }

      hope this helps

      with regards Karthik Harve

      T 1 Reply Last reply
      0
      • K Karthik Harve

        try this javascript function

        //cntrl- ID of the parent Check box
        //grd - Cliend ID of the HTML Table or GridView in which all the check boxes
        // are present
        // indCat - 1 or 2 indicates call from parent or child

        function SelectAll(cntrl,grd,indCat)
        {
        var grdComp = document.getElementById(grd);

        if(indCat == '1')    
        {
            for(i=1;i<=grdComp.getElementsByTagName('input').length-1;i++)
            {
                grdComp.getElementsByTagName('input')\[i\].checked = cntrl.checked;
            }
        }
        else if(indCat == '2')
        { 
            var chkInd = true;
            for(i=1;i<=grdComp.getElementsByTagName('input').length-1;i++)
            {                 
                if(grdComp.getElementsByTagName('input')\[i\].checked == false)
                {
                    chkInd = false;
                }                    
            }
            grdComp.getElementsByTagName('input')\[0\].checked = chkInd;             
        }
        

        }

        hope this helps

        with regards Karthik Harve

        T Offline
        T Offline
        tomorrow_ft
        wrote on last edited by
        #3

        thanks for your answer but my problem is that I have to check header checkbox twice.this works only when I check twice so when it works,header check seems not check

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups