在GridView控件上,随着鼠标的移动,高亮显示鼠标所在行,主要在GridView控件的RowDataBound事件中实现。代码如下:
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if(e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes.Add("onmouseover", "currentcolor=this.style.backgroundColor;this.style.backgroundColor='#6699ff'");
e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=currentColor;");
}
}
效果展示: