GridView控件检查所有复选框问题 [英] Gridview Checking all checkboxes issue

查看:147
本文介绍了GridView控件检查所有复选框问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的GridView的选择所有复选框功能<一个href=\"http://blog.digitaltools.com/post/2009/02/11/Checking-All-CheckBoxes-in-a-GridView-Using-Client-Side-Script.aspx\"相对=nofollow>此处。这里使用的脚本有一个问题。

I am using the gridview's select all checkbox feature from here. The script used here has one issue.

如果我选择了头复选框,所有的模板(行)复选框被选中。如果我再取消选择所有模板checbox,头checbox仍然检查。如何取消在这种情况下,头复选框?

If i select the header checkbox, all the template (rows) checkbox gets selected. If i then deselect all the template checbox, the header checbox still remains checked. How to deselect the header checkbox in that case?

请指教!

推荐答案

首先,我想一个CSS类添加到 CheckBox1 供以后使用类=CHK-所有

Firstly, I would add a Css Class to CheckBox1 for use later class="chk-all".

然后,添加一个JavaScript函数来ItemTemplate中复选框。

Then, add a javascript function to the ItemTemplate checkbox.

<ItemTemplate>
    <asp:CheckBox ID="CheckBox1" runat="server" onclick="UnselectAllOption()"  />
</ItemTemplate>

然后,用一些jQuery选择具有复选框类=CHK-所有

function UnselectAllOption(){  
    $('.chk-all').attr("checked", false");  
}

我作为其他复选框之一被点击,因为无论选择任何和你正在选择单个之一,所以在HeaderTemplate中的复选框不应该检查尽快将此设置为未选中状态。或所有的复选框都已经检查,这意味着,当你正在改变别人的一个不被检查的人在HeaderTemplate中不应该被检查。

I set this to unchecked as soon as one of the other checkboxes is clicked because either none are selected and you are selecting a single one, so the checkbox in the HeaderTemplate should not be checked. OR all the checkboxes are already checked which means that the one in the HeaderTemplate should not be checked as you are changing one of the others to not being checked.

修改

P.S。这个答案需要你的脚本参考添加到 的jQuery JavaScript库。

p.s. this answer requires you to add a script reference to the jQuery javascript library.

这篇关于GridView控件检查所有复选框问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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