//Function used is from the MSDN article "Extending the GridView Control" by Dino Esposito, May 2006.
function CheckAll(me)
{
    // Assume the ID of this element is controlID_HeaderButton 
    // (i.e. GridView1_HeaderButton)

    var index = me.name.indexOf('_');  
    var prefix = me.name.substr(0,index); 

    // Looks for the right checkbox
    for(i=0; i<document.forms[0].length; i++) 
    { 
        var o = document.forms[0][i]; 
        if (o.type == 'checkbox') 
        { 
            if (me.name != o.name) 
            {
                if (o.name.substring(0, prefix.length) == prefix) 
                {
                    // Needs to set the state of the header to any child 
                    // checkbox. To avoid passing too many parameters, 
                    // sets state by simulating the click. To ensure that 
                    // the click sets the checkbox to the "me.checked" 
                    // state, it must first the current value. 
                    o.checked = !me.checked; 
                    o.click(); 
                }
            }
        } 
    } 
}


//Used to uncheck the headers check box if a row check box is unchecked.
function UncheckHeaderCheckBox(me, HeaderCheckBoxID)
{
  var checkbox = document.getElementById(HeaderCheckBoxID);
  
  if(me.checked == false)
  {
    checkbox.checked = false;
  }
}