Saturday, August 8, 2009

Useful JavaScripts for DataGrid control






This codes will help you with your datagrid activities.
You have to add a CheckBox to datagrid.

HTML Code


this html tag adds a checkbox to header 1-add asp:TemplateColumn tag
2-add HeaderTemplate tab
3-add input tag with id=checkAll,type=checbox,onclick=DGSelectOrUnselectAll('DataGrid1',this,'chkDel')

this html tag adds checkbox to datagrid 1-add ItemTemplate tag
2-add asp checkbox control within ItemTemplate tag with id=chkDel,RunAt=server


JavaScript codes:Add these js code in
section of HTML

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);
}
}

If you have question please email me at johnstalley@live.com
My name is Talley Ouro,Developer in Raleigh,NC

No comments:

About Me

My photo
Raleigh, NC, United States
I am a software developer based in Raleigh,NC,USA.I design softwares and systems ;i also do consulting for companies worldwide.I program with these languages:VB.NET 2003/2005/2008;C#;Java(fun),SQL(200,2005,2008);ASP.NET 2.0/3.5;ASP.NET AJAX;ASP.NET MVC;JavaScript;JQuery;Windows Workflow Foundation;Web Services.I have 4 years + in programming.