Changing GridView Row Color OnMouseOver

原文:http://gridviewguy.com/ArticleDetails.aspx?articleID=172
文章介绍了鼠标在GridView控件的行间移动时改变行间颜色的技术

方法是在GridView的RowCreated事件触发时对e.Row.Attributes属性进行操作,
为其添加onmouseover和onmouseout事件
如下:
protected void MyGridView_RowCreated(object sender, GridViewRowEventArgs e)

{

string onmouseoverStyle = "this.style.backgroundColor='blue'";

string onmouseoutStyle = "this.style.backgroundColor='#@BackColor'";

string rowBackColor = String.Empty;

if (e.Row.RowType == DataControlRowType.DataRow)

{

if (e.Row.RowState == DataControlRowState.Alternate)

rowBackColor = MyGridView.AlternatingRowStyle.BackColor.Name.Remove(0, 2);

else rowBackColor = MyGridView.RowStyle.BackColor.Name.Remove(0, 2);

e.Row.Attributes.Add("onmouseover", onmouseoverStyle);

e.Row.Attributes.Add("onmouseout", onmouseoutStyle.Replace("@BackColor",rowBackColor));

}

}


posted on 2006-08-04 00:06  stswordman  阅读(742)  评论(2编辑  收藏  举报