Use JavaScript to traverse the DataGrid and datalist controls on the client, such as selecting all items in MSN.

Source: Internet
Author: User
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.