Use JavaScript to traverse the DataGrid and datalist controls on the client, such as selecting all items in MSN.
Just read the. NET traversal datalist control, like selecting all in MSN
OfArticleI suddenly remembered that I had also done a similar function, that is, to loop the rows in the control once, so that a PostBack will be generated and the service end should process it, I think this seems to be a waste of resources.
See the DataGrid below.Code
< ASP: templatecolumn Headertext = "Delete an article" >
< Headertemplate >
Delete an article
< Input Type = "Checkbox" ID = "Checkdel" Title = "Select all/cancel all delete Articles" Onclick = "Checkdelbox (this )" /> < Font Color = # Ff0000 Size = 1 > Select All/cancel all </ Font >
</ Headertemplate >
< Itemtemplate >
< ASP: checkbox ID = "Deletecheckbox" Runat = "Server" Autopostback = "False" > </ ASP: checkbox >
</ Itemtemplate >
</ ASP: templatecolumn >
When selecting the selection box of ID = "checkdel", you must select all and cancel deletecheckbox in the template.
I called JS
Function Checkdelbox (box)
{
For ( VaR I = 0 ; I < Document. form1.elements. length; I ++ )
{
VaR E = Document. form1.elements [I];
If (E. Type = 'Checkbox '))
{
VaR O = E. Name. lastindexof ('deletecheckbox ');
If (O ! =- 1 )
{
E. Checked = Box. checked;
}
}
}
}
Note This code
VaR o = E. Name. lastindexof ('deletecheckbox ');
In some cases, the ID is not displayed on the client as the id you specified in aspx, but as the control. clientid, such as some server-side controls placed in the DataGrid.Source codeWe can see that the ID is similar to the value of datagrid1 _ ctl5_hyperlink1 instead of the ID you specified.
So I have to make a decision.
You can also refer
Http://www.cnblogs.com/lovecherry/archive/2005/03/25/125516.html