If i select checkbox in grid header template i shld get all my checkbox in item template to be checked.. can any one help me to do.

chkh.Attributes.Add("onclick", "javascript:return SelectAll(this,'"+ dglist.ClientID +"');");

//dglist is gridview 
 function SelectAll(id,dg)
        {
    
                     var grid = $get(dg);
                    var cell;
      var txt;
   
            if (grid.rows.length > 0)
            {
                //loop starts from 1. rows[0] points to the header.
                for (i=1; i<grid.rows.length; i++)
                {
                        var inputs = grid.getElementsByTagName("input");
                        if (inputs.length>0)
                           {
//loop starts from 1. rows[0] points to the header.
                             for (i=1; i<inputs.length; i++) //if childNode type is CheckBox 
                             {
                           
                                                                         
                                                      if(inputs[i].type=="checkbox")
                                                        {
                                        
                                                                       var chk=$get(inputs[i].id);
                                            
                                                                        if(id.checked == true)
                                                                             {
                                                                            
                                                                chk.checked=true;
                                                                                 
                                                            
                                                              
                                                                               }
                                                                          else
                                                                                                {
                                                                                                                                                                                                              chk.checked=false;
                                                                                                      
                                                                          
                                                                                                                                                                                                          }

                                           
                                        }
                             }
                           }

                }
            }
        }
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.