检查GridView的所有复选框 [英] Check all CheckBoxes in GridView

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

问题描述

我在ASP.NET/C#一个GridView与CheckBoxField字段,一个BoundField和2 ButtonFields。共有4人有一个标题明确,其中列代表。在Page_Load事件我设置在GridView的ВataЫource我的填充数据表。

I have a GridView in ASP.NET/C# with a CheckBoxField, a BoundField and 2 ButtonFields. All 4 of them has a header to make clear where the column stands for. At the Page_Load event I set the ВataЫource of the GridView to my filled DataTable.

欲使其更容易使用的用户,并希望使在标题的复选框。当该复选框被用户选中,所有CheckBox应在GridView进行检查。我已经设置了CheckBoxField字段的HEADERTEXT到<输入类型=复选框/> ,它表明在头一个复选框现在

I want to make it easier to use for the user, and want to make a checkbox in the header. When that checkbox is checked by the user, all CheckBoxes should be checked in the GridView. I have set the HeaderText of the CheckBoxField to <input type='checkbox' />, and it shows a checkbox in the header now.

现在我想一个函数添加到该复选框,即它的选中时,所有的复选框将被选中恩反之亦然。我试图用jQuery做,但它没有工作,因为我无法找到一个方法,让所有复选框在GridView相同的ID或名字。

Now I want to add a function to that checkbox, that when it's checked, all CheckBoxes will be checked en vice versa. I tried to do it with jQuery, but it didn't work because I can't find a way to give all the CheckBoxes in the GridView the same ID or NAME.

有没有当我检查头中的基于HTML的复选框时发生的事件?如果是,哪些事件? 如果没有,我怎么能触发一个事件,当我检查复选框,并从我的code-后面改变GridView的。

Is there a event that occurs when I check the HTML based checkbox within the header? If yes, which event? If no, how can i trigger a event when I check that checkbox, and change the GridView from my code-behind.

如果没有这是可能的,我怎么能做到这一点的另一种方法,使用JavaScript,jQuery的或者有ASP.net控制。

And if none of that is possible, how can i do it on another way, with javascript, jQuery or maybe with a ASP.net control.

我希望你能帮助我这个,但请不要期望我是一个code大师。我是一个实习生在一家公司,其中需要一个系统,使用这一功能。

I hope you can help me with this, but please don't expect i'm a code guru. I'm a intern at a company where the need a system, with this functionality.

更新:

谢谢大家帮助我。是什么让数据源返回到数据表的最简单的方法,因为我需要知道我们选择了行,哪些不是?

Thank you everyone for helping me out. What is the easiest way to get the DataSource back into the DataTable, because i need to know which rows were selected and which were not?

推荐答案

使用jQuery,你在GridView里面的所有复选框,然后对每一个你更改状态,只要你喜欢。您可以从一个链接或按钮,或者你喜欢什么有史以来的onclick调用这个javascript函数。

Using jQuery, you get all the check boxes inside the GridView, and then for each one you change the status as you like. You call this javascript function from onclick of a link or a button, or what ever you like.

function CheckAll()
{   
    var updateButtons = jQuery('#<%=gvGridViewId.ClientID%> input[type=checkbox]');

    updateButtons.each( function() {
            // use this line to change the status if check to uncheck and vice versa
            //  or make it as you like with similar function
        jQuery(this).attr("checked", !this.checked);
    });     
}

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

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