由于dotnet中获得到的RowStyle中color为System.Drawing.Color类的,所以首先需要将其转换成HTML能够接受的#xxxxxx形式。写了一个函数:
下边的程序就是个间隔行设置Attribute的行为:
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}
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}
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}