Click here to Skip to main content
15,910,234 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi sir,

I am taking one datagrid. In that grid I am taking checkboxes and out side of the datagrid I am taking 2 html buttons i.e., Select All and Select None.

If I click on select all button then all check boxes are selected in grid and if I click select none button all checkboxes are unchecked.

How to write javascript function todo this? Please give a sample code for this.

Thanks
Posted
Updated 28-Aug-10 1:26am
v2

This is such a Google question...

Something like:
JavaScript
function CheckAll(sp)
{
  function CheckAll(sp)
  {
    var isChecked = sp.checked;    
    var thisItem = sp.id;    
    var items = sp.parentNode.parentNode.getElementsByTagName("input");    
    for (i=0; i<items.length;>    {
        if (items[i].id != thisItem && items[i].type=="checkbox")
        {
            if (isChecked)
            {
                items[i].checked = true;
            }
            else
            {
                items[i].checked = false;
            }            
        }
    }
  }
}


Look here[^]. For you the Javascript trigger is the two buttons outside.
 
Share this answer
 
Comments
Dalek Dave 28-Aug-10 7:28am    
Good answer
Ankur\m/ 28-Aug-10 7:51am    
Sandeep, the link you have given is for a different requirement (read my comment in the post by John_Paul where you asked clarification). I am adding an answer with correct link. :)
Try this[^]!
 
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