选中使用JQuery取消选中Gridview中的所有复选框 [英] Check Uncheck All Checkboxes in Gridview Using JQuery

查看:60
本文介绍了选中使用JQuery取消选中Gridview中的所有复选框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这里没有在所有复选框中工作原因?



jquery





< script type =text / javascriptlanguage =javascript>



功能CheckAll(复选框){

var GridView1 = document.getElementById(<%= GridView1.ClientID%>);

for(i = 1; i< GridView1.rows.length; i ++){

GridView1.rows [i] .cells [3] .getElementsByTagName(INPUT)[0] .checked = Checkbox.checked;

}

}



< / script>



ASP.Code



< asp:GridView ID =GridView1runat =serverAutoGenerateColumns =FalseDataSourceID =SqlDataSource1Width =624pxCssClass =grid

AllowPaging =TrueAllowSorting =TrueBackColor =WhiteOnRowEditing =GridView1_RowEditingOnRowCancelingEdit =GridView1_RowCancelingEdit

BorderColor =#CCCCCCBorderStyle =NoneBorderWidth =1pxCellPadding =3PageSize =5

OnRowUpdating =GridView1_RowUpdatingDataKeyNames =id>



< columns> < asp:TemplateField>

< HeaderTemplate>

< asp:CheckBox ID =chkHeaderrunat =serveronclick =CheckAll(this)/ >

< / HeaderTemplate>

< itemtemplate>

< asp:CheckBox ID =chkchildrunat =server />





< asp:BoundField DataField =idHeaderText =idSortExpression =idInsertVisible =假ReadOnly =True/>

< asp:BoundField DataField =updatedbyHeaderText =updatedbySortExpression =updatedby/>

< ; asp:BoundField DataField =usernameHeaderText =usernameSortExpression =username/>

< asp:BoundField DataField =passwordHeaderText =passwordSortExpression =password />

< asp:BoundField DataField =mailHeaderText = mailSortExpression =mail/>



< asp:BoundField DataField =imagenameHeaderText =imagenameSortExpression =imagename/> < br $> b $ b



< asp:ImageField DataImageUrlField =uploadimageHeaderText =uploadimageControlStyle-Width =80ControlStyle-Height = 100>

< controlstyle height =100pxwidth =80px>





< asp:CommandField ShowEditButton =True/>







< footerstyle backcolor =白色forecolor =#000066>

< HeaderStyle BackColor =#006699Font-Bold =TrueForeColor =White/>

< pagerstyle backcolor =Whiteforecolor =#000066horizo​​ntalalign =Left>

< rowstyle forecolor =# 000066>

< SelectedRowStyle BackColor =#669999Font-Bold =TrueForeColor =White/>

< sortedascendingcellstyle backcolor = #F1F1F1>

< sortedascendingheaderstyle backcolor =#007DBB>

< sorteddescendingcellstyle backcolor =#CAC9C9>

< sorteddescendingheaderstyle backcolor =#00547E>

here not working in all check box why?

jquery


<script type="text/javascript" language="javascript">

function CheckAll(Checkbox) {
var GridView1 = document.getElementById("<%=GridView1.ClientID %>");
for (i = 1; i < GridView1.rows.length; i++) {
GridView1.rows[i].cells[3].getElementsByTagName("INPUT")[0].checked = Checkbox.checked;
}
}

</script>

ASP.Code

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource1" Width="624px" CssClass="grid"
AllowPaging="True" AllowSorting="True" BackColor="White" OnRowEditing="GridView1_RowEditing" OnRowCancelingEdit="GridView1_RowCancelingEdit"
BorderColor="#CCCCCC" BorderStyle="None" BorderWidth="1px" CellPadding="3" PageSize = "5"
OnRowUpdating="GridView1_RowUpdating" DataKeyNames="id">

<columns> <asp:TemplateField>
<HeaderTemplate>
<asp:CheckBox ID="chkHeader" runat="server" onclick="CheckAll(this)"/>
</HeaderTemplate>
<itemtemplate>
<asp:CheckBox ID="chkchild" runat="server" />


<asp:BoundField DataField="id" HeaderText="id" SortExpression="id" InsertVisible="False" ReadOnly="True" />
<asp:BoundField DataField="updatedby" HeaderText="updatedby" SortExpression="updatedby" />
<asp:BoundField DataField="username" HeaderText="username" SortExpression="username" />
<asp:BoundField DataField="password" HeaderText="password" SortExpression="password" />
<asp:BoundField DataField="mail" HeaderText="mail" SortExpression="mail" />

<asp:BoundField DataField="imagename" HeaderText="imagename" SortExpression="imagename" />


<asp:ImageField DataImageUrlField="uploadimage" HeaderText="uploadimage" ControlStyle-Width = "80" ControlStyle-Height = "100">
<controlstyle height="100px" width="80px">


<asp:CommandField ShowEditButton="True" />



<footerstyle backcolor="White" forecolor="#000066">
<HeaderStyle BackColor="#006699" Font-Bold="True" ForeColor="White" />
<pagerstyle backcolor="White" forecolor="#000066" horizontalalign="Left">
<rowstyle forecolor="#000066">
<SelectedRowStyle BackColor="#669999" Font-Bold="True" ForeColor="White" />
<sortedascendingcellstyle backcolor="#F1F1F1">
<sortedascendingheaderstyle backcolor="#007DBB">
<sorteddescendingcellstyle backcolor="#CAC9C9">
<sorteddescendingheaderstyle backcolor="#00547E">

推荐答案

您需要使用GridView列的正确索引。



在您的情况下,索引应为0.



更改此行:

you need to use proper index of GridView column.

In your case the index should be 0.

Change this line :
GridView1.rows[i].cells[3].getElementsByTagName("INPUT")[0].checked = Checkbox.checked;







这个






with this

GridView1.rows[i].cells[0].getElementsByTagName("INPUT")[0].checked = Checkbox.checked;





让我知道它是否适合你!



let me know if it works for you!


这篇关于选中使用JQuery取消选中Gridview中的所有复选框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆