Gridview行随鼠标变色
在GridView的RowDataBound()事件添加如下代码:
1 protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
2 {
3 if (e.Row.RowType == DataControlRowType.DataRow)
4 {
5 //鼠标经过时,行背景色变
6 e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor='#E6F5FA'");
7 //鼠标移出时,行背景色变
8 e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor='#FFFFFF'");
9 }
10 }
11
12
2 {
3 if (e.Row.RowType == DataControlRowType.DataRow)
4 {
5 //鼠标经过时,行背景色变
6 e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor='#E6F5FA'");
7 //鼠标移出时,行背景色变
8 e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor='#FFFFFF'");
9 }
10 }
11
12