protected void GridView1_OnRowDataBound(object sender, GridViewRowEventArgs e)
{
int i;
for (i = 0; i < GridView1.Rows.Count + 1; i++) // 网上代码这里没有加1,发现当移入移出第一行时颜色未变。
{
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");
}
}
}
单击GridView控件,显示属性窗口,点击事件按钮,找到RowDataBound事件,然后 设计方法。