gridview行用javascript

时间:2014-01-11 18:04:25

标签: c# javascript asp.net gridview

我在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'不包含'row'的定义,没有   扩展方法'row'接受类型的第一个参数   可以找到'System.EventArgs'(你是否缺少using指令   或汇编参考?)

由于

1 个答案:

答案 0 :(得分:0)

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

RowDataBound有GridViewRowEventArgs个参数,他们需要这样做