给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;效课就出来了,这是为什么啊,请大侠帮忙解决下,不胜感激!
阿晨1998
蝴蝶不菲