CheckBox SelectAll / DeselectAll [英] CheckBox SelectAll / DeselectAll
本文介绍了CheckBox SelectAll / DeselectAll的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的网格看起来像这样..
My Grid is look like this..
col0 col1
checkbox 123
checkbox 234
empty row
checkbox 12
现在我尝试做的是我想选择所有复选框'和DeselectAll怎么做...
我正在尝试以下方式...
now what i''m try to do is i want to select All checkBox''s and DeselectAll how to do...
i''m trying in the following way...
function CheckAll(oCheckbox) {
var gdDocument = document.getElementById("<%=gdDocument.ClientID %>");
for (i = 1; i < gdDocument.rows.length; i++) {
gdDocument.rows[i].cells[0].getElementsByTagName("INPUT")[0].checked = oCheckbox.checked;
}
}
<HeaderTemplate>
<input id="chkSelect" type="checkbox" onclick="CheckAll(this)" runat="server" />
</HeaderTemplate>
<ItemTemplate>
<asp:CheckBox ID="chkSelect" runat="server" />
</ItemTemplate>
但是这个代码适用于每个&每个人都有一条记录,这段代码工作正常,但每当行复选框不可见(false)。在那种情况下,从那里开始,没有选中复选框'。
任何人都可以帮我解决这个问题......
but for this code is working for each & everyrow have a record this code is working fine , but whenever the row checkbox is not visible ( false). In that case , from there onwords the checkbox''s are not selected.
can anyone help me to resolve this issue...
推荐答案
尝试以下代码,它对我来说工作正常
try the following code, its working fine for me
protected void chekSelectALL_CheckedChanged(object sender, EventArgs e)
{
CheckBox chkA = GridView1.HeaderRow.FindControl("chekSelectALL") as CheckBox;
foreach (GridViewRow gv in GridView1.Rows)
{
CheckBox chkS = gv.FindControl("chekSelect") as CheckBox;
if (chkA.Checked)
{
chkS.Checked = true;
}
else
{
chkS.Checked = false;
}
}
}
这篇关于CheckBox SelectAll / DeselectAll的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文