在RowDataBound中实现鼠标经过的GridView行变色

实现功能:鼠标经过,GridView行变色。代码如下:

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            DataRowView dv = (DataRowView)e.Row.DataItem;
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                string str = @"javascript:window.open('Detail.aspx?id=" + dv.Row["Id"].ToString() + "');";
                e.Row.Attributes.Add("onclick", str);
                e.Row.Attributes.Add("style", "cursor:hand");
                e.Row.Attributes.Add("onmouseover", "OldStyle=this.style.backgroundColor;this.style.backgroundColor='#f4f1cc';");
                e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=OldStyle");
            }
        }

 

posted @ 2013-09-06 10:40  人生只若初见  阅读(228)  评论(0编辑  收藏  举报