Here is the ASP code
//
// this html tag adds checkbox to header
//
onclick="DGSelectOrUnselectAll('DataGrid1',this,'chkDel')" >
//
// this html tag adds checkbox to datagrid
Below is the Java Script
//-------------------------------------------------------
//this is to select or unselect the datagrid check boxes
function DGSelectOrUnselectAll(grdid,obj,objlist){
//this function decides whether to check or uncheck all
if(obj.checked)
DGSelectAll(grdid,objlist)
else
DGUnselectAll(grdid,objlist)
}
//----------
function DGSelectAll(grdid,objid){
//.this function is to check all the items
var chkbox;
var i=2;
chkbox=document.getElementById(grdid +
'__ctl' + i + '_' + objid);
while(chkbox!=null){
chkbox.checked=true;
i=i+1;
chkbox=document.getElementById(grdid +
'__ctl' + i + '_' + objid);
}
}//--------------
function DGUnselectAll(grdid,objid){
//.this function is to uncheckcheck all the items
var chkbox;
var i=2;
chkbox=document.getElementById(grdid +
'__ctl' + i + '_' + objid);
while(chkbox!=null){
chkbox.checked=false;
i=i+1;
chkbox=document.getElementById(grdid +
'__ctl' + i + '_' + objid);
}
}
//-------------------------------------------------------
THIS IS USEFUL TO CHECK OR UNCHECK CHECKBOXES IN A GRID.
PS: THIS ONLY AFFECTS THE CURRENT PAGE CONTENTS OF THE GRID.
IF YOU NEED THE SAME TO AFFECT ALL OTHER PAGES, THEN WE NEED TO CUSTOMISE THE ABOVE CODE
BY ADDING A HIDDEN VARIABLE AND SETTING IT TO SOME VALUE WHICH IF SET, THEN CHECKS ALL CHECK BOXES
WHEN WE LOAD THE PAGE.

0 comments:
Post a Comment