如何实现鼠标指向GridView控件的行时,该行改变颜色,离开该行时又恢复原来的颜色?
如何实现鼠标指向GridView的行时,该行改变颜色,离开该行时又恢复原来的颜色???这个肯定要用到JavaScript脚本了吗?还是GridView控件本身有此功能???
protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
{
if ((e.Row.RowState == DataControlRowState.Normal || e.Row.RowState == (DataControlRowState.Selected | DataControlRowState.Normal)) && e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor='#B1CFF8'");
e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor='#E3EAEB';");
}
if ((e.Row.RowState == DataControlRowState.Alternate || e.Row.RowState == (DataControlRowState.Selected | DataControlRowState.Alternate))
&& e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor='#B1CFF8'");
e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor='White';");
}
}
测试通过,但目前还未完全看明白代码的意思。