JavaScript implementation Griwview single-column full selection (self-write code) _javascript tips

Source: Internet
Author: User

In the GridView, there is a series of Checkbox, which is to be selected or all optional. Started looking on the Internet, but the reference code will select all the Checkbox in the GridView, and I want a single column selection. As shown in figure:

Auditing and permissions are to be separated.


I wrote JavaScript code myself and posted it for everyone's reference.

Copy Code code 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 < J + +) {
var id = "Ctl00_contentplaceholder1_gridview1_ctl0" + j + "_checkbox1";
if (items[i].id = = ID) {
items[i].checked = checkall.checked;
}
}
}
}
}

Where the IDs of lines J and 6th of line 5th are used to determine the Checkbox in the same column, the range and ID of the specific J may be different and can be passed through alert (items[i].id); Traverse the entire items to view the corresponding IDs.
The corresponding code for the front desk is as follows:
Copy Code code as follows:

<asp:templatefield headertext= "Audit" >
<HeaderTemplate>
<asp:checkbox id= "Chkall" onclick= ' Chkall (this) ' runat= ' server '/>
Audit
</HeaderTemplate>
<ItemTemplate>
<asp:checkbox id= "CheckBox1" checked= ' <%# Eval ("Ischeck")%> ' runat= ' server '/>
</ItemTemplate>
<itemstyle horizontalalign= "Center" width= "100px"/>
</asp:TemplateField>

Related Article

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.