gridview中的多个复选框列 [英] multi checkbox columns in gridview

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

问题描述

大家好,我是新来的,没有最好的英语,我会尽我所能让我理解

现在,我的gridview有一个小问题.
我试图在我的grdiview中放入带有复选框的4列,每个列的标题中都有一个唯一的复选框,并且我试图使该标题的复选框成为"selectAll复选框" ...每个列1
我在第一个复选框列中有此代码..当我选中此复选框时,每个列中的每个复选框都被选中了,我该怎么办?

hi everybody, im new here and a dont have the best inglish, I will do my best to make me understand

now, i have a litle problem with my gridview.
im trying to put 4 columns with checkboxs into my grdiview, each colum has a unique checkbox in the header and im try to make that header checkbox a "selectAll checkbox"... 1 for each colum

i have this code in the first checkbox colum.. when i select this checkbox, each checkbox in every colum was checked, what can i do?

 <script language="javascript" type="text/javascript">
       function SelectAll(Id) {
           var myform = document.forms[0];
           var len = myform.elements.length;

           document.getElementById(Id).checked == true ? document.getElementById(Id).checked = false : document.getElementById(Id).checked = true;

           for (var i = 0; i < len; i++) {
               if (myform.elements[i].type == 'checkbox') {
                   if (myform.elements[i].checked) {
                       myform.elements[i].checked = false;
                   }
                   else {
                       myform.elements[i].checked = true;
                   }
               }
           }
       }
</script>

推荐答案

hey
试试这个.
hey
try this.
function CheckAll(checkboxId, index) {
            var grid = document.getElementById('GridView1');

            if (grid.rows.length > 0) {
                //loop starts from 1. rows[0] points to the header.
                for (i = 1; i < grid.rows.length; i++) {
                    //get the reference of first column
                    if (index > 0) {
                        cell = grid.rows[i].cells[index];
                        for (j = 0; j < cell.childNodes.length; j++) {
                            //if childNode type is CheckBox
                            if (cell.childNodes[j].type == "checkbox") {
                                //assign the status of the Select All checkbox to the cell checkbox within the grid
                                cell.childNodes[j].checked = checkboxId.checked;
                            }
                        }

                    }
                }
            }
        }



//调用函数



//Calling of function

<HeaderTemplate>
                                                                                <asp:CheckBox ID="chkHeader" Text="Check" runat="server" ToolTip="Check All" onclick="return CheckAll(chkHeader,columnNo);" />
                                                                            </HeaderTemplate>



这对我有用
尝试重播
祝你好运



This works for me
try and give replay
Best Luck


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

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