JavaScript implements a Single-Column Selection of GriwView (self-writing code)

Source: Internet
Author: User

There are a series of checkboxes in the GridView. You need to select all or all of them. I found it online, but the reference code Selects all the checkboxes in the GridView, and I want all of them in a single column.

Audit and permissions must be separated.


I wrote JavaScript code and posted it for your reference.

Copy codeThe Code is as follows: function chkAll (CheckAll ){
Var items = document. getElementsByTagName ("input ");
For (var I = 0; I <items. length; I ++ ){
If (items [I]. type = "checkbox "){
For (var j = 2; j <10; j ++ ){
Var id = "ctl00_ContentPlaceHolder1_GridView1_ctl0" + j + "_ CheckBox1 ";
If (items [I]. id = id ){
Items [I]. checked = CheckAll. checked;
}
}
}
}
}

The IDS of Row j and row 5th of row 6th are used to determine the Checkbox of the same column. The range and id of the specific column j may be different. You can use alert (items [I]. id); traverse the entire items to view the corresponding id.
The front-end code is as follows:Copy codeThe Code is as follows: <asp: TemplateField HeaderText = "Review">
<HeaderTemplate>
<Asp: CheckBox ID = "chkAll" onclick = 'chkall (this) 'runat = "server"/>
Review
</HeaderTemplate>
<ItemTemplate>
<Asp: CheckBox ID = "CheckBox1" Checked = '<% # Eval ("isCheck") %> 'runat = "server"/>
</ItemTemplate>
<ItemStyle HorizontalAlign = "Center" Width = "100px"/>
</Asp: TemplateField>

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.