I have a string value that is returned from the database. the value will always either be “Red” or “Green”. I am trying to change the forecolor of a label in my repeater based on this string value. If the value is “Red” the forecolor of the label should be red and visa versa.
I try by using this code in my asp page:
ForeColor='<%# Eval("Color")%>'
however I get the flowing error:
Specified cast is not valid.
I have had a similar problem before by trying to set the width of an image dynamically and ended up casting the value like this:
<asp:Image
ID="Image1"
runat="server"
Width='<%# System.Web.UI.WebControls.Unit.Parse(Eval("ImageSize").ToString()) %>'
ImageUrl="~/Images/ProgressBar.jpg"/>
The problem is how do I use the same technique with a system color?
ForeColorneeds aColorobject not a string.So you could use
ColorTranslator.FromHtml: