Edwin Wang's Blog

If there were no clouds, we should not enjoy the sun~~~ edwin-wang.com

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::
由于dotnet中获得到的RowStyle中color为System.Drawing.Color类的,所以首先需要将其转换成HTML能够接受的#xxxxxx形式。写了一个函数:
 1string toWebColor(System.Drawing.Color theColor)
 2{
 3if (Convert.ToString(theColor.R, 16== "0" && Convert.ToString(theColor.G, 16== "0" && Convert.ToString(theColor.B, 16== "0")
 4{
 5return "#ffffff";
 6}

 7else
 8{
 9return "#" + Convert.ToString(theColor.R, 16+ Convert.ToString(theColor.G, 16+ Convert.ToString(theColor.B, 16);
10}

11}


下边的程序就是个间隔行设置Attribute的行为:
 1if (e.Row.RowType == DataControlRowType.DataRow)
 2{
 3if (e.Row.RowState == DataControlRowState.Normal)
 4{
 5e.Row.Attributes.Add("onmouseover""this.style.backgroundColor='orange'");
 6e.Row.Attributes.Add("onmouseout""this.style.backgroundColor='" + toWebColor(GridView.RowStyle.BackColor) + "'");
 7}

 8else if (e.Row.RowState == DataControlRowState.Alternate)
 9{
10e.Row.Attributes.Add("onmouseover""this.style.backgroundColor='orange'");
11e.Row.Attributes.Add("onmouseout""this.style.backgroundColor='" + toWebColor(GridView.AlternatingRowStyle.BackColor) + "'");
12}

13else
14return;
15}

posted on 2009-05-13 20:35  laughterwym  阅读(640)  评论(0编辑  收藏  举报