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