给Gridview换背景代码如下 protected void Users_View_RowDataBound(object sender, GridViewRowEventArgs e) { for (int i = 0; i < Users_View.Rows.Count; i++) { //首先判断是否是数据行 if (e.Row.RowType == DataControlRowType.DataRow) { //当鼠标停留时更改背景色 e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='#00A9FF'"); //当鼠标移开时还原背景色 e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c"); } } }出现的现象是数据行第一行的背景不发生改变。当把i的初始值赋为i=-1;效课就出来了,这是为什么啊,请大侠帮忙解决下,不胜感激!
2 回答

阿晨1998
TA贡献2037条经验 获得超6个赞
你的第一行是数据行不是?可以使用下面的方法:直接放到Users_View_RowDataBound下
//如果是绑定数据行
if (e.Row.RowType == DataControlRowType.DataRow)
{
//鼠标经过时,行背景色变
e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor='#E6F5FA'");
//鼠标移出时,行背景色变
e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor='#FFFFFF'");
}
参考链接:http://blog.csdn.net/fanweiwei/archive/2007/03/26/1541373.aspx
- 2 回答
- 0 关注
- 500 浏览
添加回答
举报
0/150
提交
取消