GridView Header复选框更改在ie9中不工作

GridView Header Checkbox Change is not working in IE 9

本文关键字:ie9 工作 Header 复选框 GridView      更新时间:2023-09-26

NET 2.0 Web应用程序中,有一个网格视图,其中行是动态创建的,第一列作为复选框。用户可以选中GridView行中的单个复选框,也可以只选中Check All来选中GridView中的所有行。

我添加了一个模板字段标题模板(标题行)和项目模板(数据行)。我已经添加了javascript方法来检查所有的数据行复选框,当用户点击标题行复选框在GridView_RowDataBound事件。

Javascript函数通过"getElementById('GridViewName')获取GridView,并检查行的第一个单元格类型是否为复选框,然后选中该复选框。

    //get gridview from the document
    var grid = document.getElementById(gridId);
    //total rows in the gridview
    var rowsCount = grid.rows.length;
    //cond: sent by header checkbox 
    if (bIsHeader == true) {
        //loop starts from 1. rows[0] points to the header.
        for (i = 1; i < rowsCount; i++) {
            //get the reference of first column
            cell = grid.rows[i].cells[0];
            //cond: confirm type of the cell child
            if (cell.childNodes[0].type == "checkbox") {
                //assign header checkbox state to every row
                cell.childNodes[0].checked = chkBox;
            }
        }
    }

在ie8及更低版本中工作正常。但是,在ie9中,当这个javascript函数来获取childNodes的row来检查它是否是复选框。它不介入。

我想修复什么?

在我的代码中,行。childNodes不能在ie9中工作。在ie9及以上版本中,此属性的替代选项是什么?

行。children属性可以帮助我完成这个任务