Javascript 如何选中/取消选中外部按钮的Gridview复选框
如何从按钮切换gridview复选框?我只想使用Javascript 我正在使用以下代码进行网格视图:Javascript 如何选中/取消选中外部按钮的Gridview复选框,javascript,asp.net,gridview,Javascript,Asp.net,Gridview,如何从按钮切换gridview复选框?我只想使用Javascript 我正在使用以下代码进行网格视图: <asp:GridView ID="gvWrkLogVW" runat="server" AutoGenerateColumns="False" GridLines="None" BorderStyle="None" ShowHeader="False"> <Columns> <asp:TemplateField>
<asp:GridView ID="gvWrkLogVW" runat="server" AutoGenerateColumns="False" GridLines="None" BorderStyle="None" ShowHeader="False">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:CheckBox ID="chkWorklog" runat="server"></asp:CheckBox>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="The_Text" />
</Columns>
</asp:GridView>
我想从外部按钮访问CodeGridView复选框
<asp:Button ID="btncheck" runat="server" Text="Check All" OnClientClick="SelectAll()" />
我正在编写下面的javascript,但它不起作用
function SelectAll() {
var gridViewControl = document.getElementById('<%= gvGetAllCircuits.ClientID %>');
for (i = 0; i < gridViewControl.rows.length; i++) {
if (gridViewControl.elements[1].type == "checkbox") {
gridViewControl.elements[1].checked = true;
}
}
}
函数SelectAll(){
var gridViewControl=document.getElementById(“”);
对于(i=0;i
JS
function SelectAll() {
var gridViewControl = document.getElementById('<%= gvGetAllCircuits.ClientID %>');
for (i = 0; i < gridViewControl.rows.length; i++) {
//loop starts from 1. rows[0] points to the header.
for (i=1; i<gridViewControl.rows.length; i++)
{
//get the reference of first column - if you have a header
cell = gridViewControl.rows[i].cells[0];
//loop according to the number of childNodes in the cell
for (j=0; j<cell.childNodes.length; j++)
{
//if childNode type is CheckBox
if (cell.childNodes[j].type =="checkbox")
{
//assign the status of the Select All checkbox to the cell checkbox within the grid
cell.childNodes[j].checked = "true";
}
}
}
}
}
函数SelectAll(){
var gridViewControl=document.getElementById(“”);
对于(i=0;i 对于(i=1;i aspx的输出看起来如何?Gridview中是否有标头?问题可能是您的循环索引