复选框全部选中 [英] CheckBox Slecect All
本文介绍了复选框全部选中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好
我有一个GridView,因为我正在使用CheckBoxes,我想一次选择所有CheckBoxes,因为我编写了这样的代码
Hi everyone
I have a GridView in that i''m using CheckBoxes,i want select All checkBoxes at a time for that i wrote code like this
protected void chkSelectAllTo_CheckedChanged(object sender, EventArgs e)
{
CheckBox chk;
foreach (GridViewRow rowItem in gvTo.Rows)
{
chk = (CheckBox)(rowItem.Cells[0].FindControl("chkSelect"));
chk.Checked =((CheckBox)sender).Checked;
}
}
<asp:CheckBox ID="chkSelectAllTo" runat="server" Text="Select All" AutoPostBack="true" OnCheckedChanged="chkSelectAllTo_CheckedChanged" />
它工作正常,但是我不想每次都回发,因为我删除了AutoPostBack 属性.但是没有任何人可以帮助我做到这一点.
谢谢您,
it''s working perfectly,but i don''t want postback on everytime,for that i remove AutoPostBack property.But it''s not working can anyone plz help me to do this.
Thank u,
推荐答案
如何避免在复选框的checkchange事件? [ ^ ]
在按钮ASP.NET c#上禁用回发 [ ^ ]
并查看 ^ ]了解更多信息.
how to avoid postback on the checkbox''s checkchange event?[^]
Disable Postback on button ASP.NET c#[^]
and look here[^] for more.
可以使用客户端脚本解决此问题.
现在,您的复选框将如下所示:
This problem can be solve using client side script.
Now Your Checkbox will look like
<pre lang="HTML">
<asp:checkbox id="chkSelectAllTo" runat="server" text="Select All" onclick="SelectAll(this)" xmlns:asp="#unknown" />
并处理以下"SelectAll"事件,请编写以下脚本.
and to handle this ''SelectAll'' event write following script.
<pre lang="HTML">
<script type=''text/javascript''>
function SelectAll(chkBxObj)
{
var gridObj = document.getElementById(''GridObjID'');
for(var index = 0 ; index < gridObj.rows.length; index++)
{
//find here your checkbox objects in Grid Row,
var checkBoxObj = gridObj.rows[index].children[0].children[0]; // You have to mention here exact depth of your check box Control in Grid View Row.
//now set check box check/Uncheck
checkBoxObj.checked = chkBxObj.checked;
}
return false
}
</script>
使用Jquery进行此操作
首先添加jquery库的引用
Use Jquery for doing this
First add reference of jquery library
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script></script>
然后为您的网格视图复选框提供一些类名称,例如
Then give some class name for your grid view checkbox for eg
class="myCheckbox"
然后添加此脚本
Then Add this script
<script type="text/javascript">
这篇关于复选框全部选中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文