由于dotnet中获得到的RowStyle中color为System.Drawing.Color类的,所以首先需要将其转换成HTML能够接受的#xxxxxx形式。写了一个函数:
下边的程序就是个间隔行设置Attribute的行为:
1
string toWebColor(System.Drawing.Color theColor)
2
{
3
if (Convert.ToString(theColor.R, 16) == "0" && Convert.ToString(theColor.G, 16) == "0" && Convert.ToString(theColor.B, 16) == "0")
4
{
5
return "#ffffff";
6
}
7
else
8
{
9
return "#" + Convert.ToString(theColor.R, 16) + Convert.ToString(theColor.G, 16) + Convert.ToString(theColor.B, 16);
10
}
11
}
string toWebColor(System.Drawing.Color theColor)2
{3
if (Convert.ToString(theColor.R, 16) == "0" && Convert.ToString(theColor.G, 16) == "0" && Convert.ToString(theColor.B, 16) == "0")4
{5
return "#ffffff";6
}7
else8
{9
return "#" + Convert.ToString(theColor.R, 16) + Convert.ToString(theColor.G, 16) + Convert.ToString(theColor.B, 16);10
}11
}下边的程序就是个间隔行设置Attribute的行为:
1
if (e.Row.RowType == DataControlRowType.DataRow)
2
{
3
if (e.Row.RowState == DataControlRowState.Normal)
4
{
5
e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor='orange'");
6
e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor='" + toWebColor(GridView.RowStyle.BackColor) + "'");
7
}
8
else if (e.Row.RowState == DataControlRowState.Alternate)
9
{
10
e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor='orange'");
11
e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor='" + toWebColor(GridView.AlternatingRowStyle.BackColor) + "'");
12
}
13
else
14
return;
15
}
if (e.Row.RowType == DataControlRowType.DataRow)2
{3
if (e.Row.RowState == DataControlRowState.Normal)4
{5
e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor='orange'");6
e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor='" + toWebColor(GridView.RowStyle.BackColor) + "'");7
}8
else if (e.Row.RowState == DataControlRowState.Alternate)9
{10
e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor='orange'");11
e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor='" + toWebColor(GridView.AlternatingRowStyle.BackColor) + "'");12
}13
else14
return;15
}




浙公网安备 33010602011771号