【问题标题】:gridview row with javascript带有javascript的gridview行
【发布时间】:2014-01-11 18:04:24
【问题描述】:

我无法在 gridview 中选择一行,我有 javascript 代码

function SelectRow(row) {
    var _selectColor = "#303030";
    var _normalColor = "#909090";
    var _selectFontSize = "3em";
    var _normalFontSize = "2em";
    // get all data rows - siblings to current
    var _rows = row.parentNode.childNodes;
    // deselect all data rows
    try {
        for (i = 0; i < _rows.length; i++) {
            var _firstCell = _rows[i].getElementsByTagName("td")[0];
            _firstCell.style.color = _normalColor;
            _firstCell.style.fontSize = _normalFontSize;
            _firstCell.style.fontWeight = "normal";
        }
    }
    catch (e) { }
    // select current row (formatting applied to first cell)
    var _selectedRowFirstCell = row.getElementsByTagName("td")[0];
    _selectedRowFirstCell.style.color = _selectColor;
    _selectedRowFirstCell.style.fontSize = _selectFontSize;
    _selectedRowFirstCell.style.fontWeight = "bold";
}

在我拥有的网格的数据绑定事件上

    protected void GridView1_DataBound(object sender, EventArgs e)
        {
          foreach (GridViewRow Row in GridView1.Rows){
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                // javascript function to call on row-click event
                e.row.Attributes.Add("onClick", "javascript:void SelectRow(this);");
            }
          }
        }

但是这条线报错

if (e.Row.RowType == DataControlRowType.DataRow) 错误消息:“System.EventArgs”不包含“行”的定义,并且没有 扩展方法“行”接受类型的第一个参数 可以找到“System.EventArgs”(您是否缺少 using 指令 还是程序集参考?)

谢谢

【问题讨论】:

    标签: c# javascript asp.net gridview


    【解决方案1】:

    您使用了不正确的事件。你使用DataBound,但需要使用RowDataBound

    RowDataBound 有 GridViewRowEventArgs 参数,他们需要方法来做到这一点

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-02-04
      • 2015-11-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多