Select all the checkbox controls in the DataGrid in Asp.net

Source: Internet
Author: User
< Script Language = " Javascript " >
Function select_deselectall (chkval, idval)
{
VaR FRM
= Document. Forms [ 0 ];

// Loop through all elements <br>
For (I = 0 ; I < FRM. length; I ++ ) {

// Look for our header template's checkbox
If (Idval. indexof ( ' Checkall ' ) ! =   - 1 ) {

// Check if main checkbox is checked, then select or deselect DataGrid checkboxes
If (Chkval =   True ) {
FRM. elements [I].
Checked = True;
}
 
Else   {
FRM. elements [I].
Checked = False;
}

// Work here with the item template's multiple checkboxes
}
 
Else   If (Idval. indexof ( ' Deletethis ' ) ! =   - 1 ) {

// Check if any of the checkboxes are not checked, and then uncheck top select all checkbox
If (FRM. elements [I]. Checked   =   False ) {
FRM. elements [
1].Checked = False;//Uncheck main select all checkbox
}

}

}

}

</ Script >

Then, checkbox is defined as follows:
< ASP: templatecolumn headertext = " Aaa " >
< Headertemplate >
< ASP: checkbox ID = " Checkall " Onclick = " Javascript: Return select_deselectall (this. Checked, this. ID ); "
Runat
= " Server " > </ ASP: checkbox > < Font face = " Webdings " Color = " White " Size = " 4 " > A </ Font >
</ Headertemplate >
< Itemtemplate >
< ASP: checkbox ID = " Deletethis " Onclick = " Javascript: Return select_deselectall (this. Checked, this. ID ); "
Runat
= " Server " > </ ASP: checkbox >
</ Itemtemplate >

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.