【问题标题】:GridView Header Checkbox Change is not working in IE 9GridView 标题复选框更改在 IE 9 中不起作用
【发布时间】:2013-05-24 07:47:13
【问题描述】:

在 ASP.NET 2.0 Web 应用程序中,有一个网格视图,其中行是动态创建的,第一列作为复选框。用户要么选中 GridView Rows 中的单个复选框,要么只选中 Check All 以检查 GridView 中的所有行。

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

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;
            }
        }
    }

在 IE 8 及更低版本中运行良好。但是,在 IE 9 中,当这个 javascript 函数来获取行的 childNodes 以检查它是否是复选框时。它不会介入。

我想解决什么问题?

在我的代码中,row.childNodes 在 IE 9 中不起作用。在 IE 9 及更高版本中此属性的替代方法是什么?

【问题讨论】:

  • 您确定该问题与 row.childNodes 有关吗?我准备了 JsFiddle example 和这个在 IE9 中工作的例子,它使用 row.childNodes 属性
  • 是的,但我现在想通了。我用 row.children 替换了 row.childNodes,它也在 IE9 和 IE 8 上运行。

标签: javascript asp.net visual-studio-2008 gridview internet-explorer-9


【解决方案1】:

row.children 属性可以帮助我完成这项任务。

【讨论】:

    猜你喜欢
    • 2014-01-07
    • 2017-08-15
    • 1970-01-01
    • 2020-02-05
    • 2011-12-14
    • 2011-10-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多