想实现单机鼠标左键选中一行,行变色,并获得这一行数据的ID,ID列我放在了cells[0],并且隐藏了。

解决方案 »

  1.   

    gridview的HTML代码是一个table,实际上你要操作的是一个table,可以用js获取当前点击对象,然后根据你的要求去获取父节点或者兄弟节点
      

  2.   

    我觉得可以通过这样做
    给GridView自动编号,然后隐藏编号这一列,
    自动编号事件处理双击GridView的OnRowDataBound事件;
    在后台的GridView1_RowDataBound()方法添加代码,最后代码如下所示:
        protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            //如果是绑定数据行 //清清月儿http://blog.csdn.net/21aspnet 
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                ////鼠标经过时,行背景色变 
                //e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor='#E6F5FA'");
                ////鼠标移出时,行背景色变 
                //e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor='#FFFFFF'");
                ////当有编辑列时,避免出错,要加的RowState判断 
                //if (e.Row.RowState == DataControlRowState.Normal || e.Row.RowState == DataControlRowState.Alternate)
                //{
                //    ((LinkButton)e.Row.Cells[6].Controls[0]).Attributes.Add("onclick", "javascript:return confirm('你确认要删除:/"" + e.Row.Cells[1].Text + "/"吗?')");
                //}
            }
            if (e.Row.RowIndex != -1)
            {
                int id = e.Row.RowIndex + 1;
                e.Row.Cells[0].Text = id.ToString();
            }
        }然后通过鼠标移动时获取当前行的第一单元格的值。