[英]Check and uncheck checkboxes in Asp.net GridView using jQuery
iam using checkboxes in gridview. 我在GridView中使用复选框。 i want to check and uncheck checkboxes in gridview using jquery. 我想使用jQuery在GridView中选中和取消选中复选框。 i tried this with live method. 我尝试用现场方法。 it's working for the first page in the gridview but not in the page index changing event. 它适用于gridview的第一页,但不适用于页面索引更改事件。
$(document).ready(function () {
var checkBoxSelector = '#<%=grv_ClientList.ClientID%> input[id*="chck_itemSelect"]:checkbox';
//header checkbox
$('[id$=chck_headSelect]').live("click", function () {
if ($(this).is(":checked")) {
$(checkBoxSelector).attr('checked', true);
}
else {
$(checkBoxSelector).attr('checked', false);
}
});
});
You can do it by iterating through each checkbox of gridview like: 您可以通过遍历gridview的每个复选框来做到这一点,例如:
<script type="text/javascript">
function CheckUnCheckAll(chk) {
$('#<%=GridView1.ClientID %>').find("input:checkbox").each(function () {
if (this != chk) {
this.checked = chk.checked;
}
});
}
</script>
Check example: http://www.codegateway.com/2012/05/jquery-check-uncheck-all-checkboxes-in.html 检查示例: http : //www.codegateway.com/2012/05/jquery-check-uncheck-all-checkboxes-in.html
Please go through the sample code. 请仔细阅读示例代码。
<script src="jquery-1.4.1.js" type="text/javascript"></script>
<script src="jquery-1.4.1-vsdoc.js" type="text/javascript"></script>
<script type="text/javascript" >
$(document).ready(function() {
var ab = 0 ;
$("[id$=myCheck]").click(function() {
if (ab == 0) {
$('#<%=GridView1.ClientID %> >tbody >tr >td:first-child > input:checkbox').attr('checked', true);
ab = 1;
}
else {
$('#<%=GridView1.ClientID %> >tbody >tr >td:first-child > input:checkbox').attr('checked', false);
ab =0 ;
}
})
})
</script>
<Columns>
<asp:TemplateField>
<HeaderTemplate>
<asp:CheckBox ID="myCheck" runat="server" />
</HeaderTemplate>
<ItemTemplate><asp:CheckBox ID="urCheck" runat="server" /></ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="UnitName" HeaderText="Unit Name" />
<asp:BoundField DataField="Description" HeaderText="Description" />
<asp:TemplateField HeaderText="Status">
<ItemTemplate>
<asp:DropDownList ID="AttendId" runat="server" >
<asp:ListItem style="Color:Green" Text="Present" Value="0"></asp:ListItem>
<asp:ListItem style="Color:Red" Text="Absent" Value="1"></asp:ListItem>
<asp:ListItem style="Color:Blue" Text="Leave" Value="2"></asp:ListItem>
</asp:DropDownList>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.