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>