Online Earning Sources (Without Investment)

If you want to post, send your post on dotnetglobe@gmail.com .Put 'Title' as 'Subject'

Pages

Thursday, July 16, 2009

Check all the Checkboxes in Gridview using Javascript

//where 'Hchkbox' is the id of Checkbox in HeaderTemplate

function SelectAll(Hchkbox)
{
//get reference of DataList/GridView control
var grid = document.getElementById("<%= DataList1.ClientID %>");

var cell;

if (grid.rows.length > 0)
{
//loop starts from 1. rows[0] points to the header.
for (i=1; i < grid.rows.length; i++)
{
//get the reference of first column
cell = grid.rows[i].cells[0];

//loop according to the number of childNodes in the cell
for (j=0; j < cell.childNodes.length; j++)
{
//if childNode type is CheckBox
if (cell.childNodes[j].type =="checkbox")
{

//assign the status of the Select All checkbox to the cell checkbox within the grid
cell.childNodes[j].checked = Hchkbox.checked;
}
}
}
}
}

No comments:

itworld