为了方便用户清晰地观察表格中的行信息时,我们经常想到给表格的行加上背景。但是固定的行背景有时并不能很好的区分出其它行,所以采用鼠标划过动态改变行的背景。
为了对比强烈,默认设置GridView的行背景为白色。
- protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
- {
- //如果是绑定数据行
- if (e.Row.RowType == DataControlRowType.DataRow)
- {
- //鼠标经过时,行背景色变
- e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor='#E6F5FA'");
- //鼠标移出时,行背景色变
- e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor='#FFFFFF'");
- }
- }