Setting BackColor of GridView cell dynamically

M

Mike P

I have a number of colours in a database linked to different conditions,
and this data is displayed in a gridview. I want to set the BackColor
of a gridview cell dependent upon this value, for example FF0000 etc.
The code I have used gives me the error 'specified cast is not valid' :

<asp:TemplateField HeaderText="Forecast Type"
SortExpression="ForecastDescription">
<ItemTemplate>
<asp:Label
ID="lblForecastType" Text='<%# Eval("ForecastDescription") %>'
BackColor='<%# Eval("ForecastColor") %>' runat="server"></asp:Label>
</ItemTemplate>
<ItemStyle Height="24px"
Width="50px" />
</asp:TemplateField>

Any ideas how to do this?
 
Joined
Aug 30, 2006
Messages
1
Reaction score
0
This one had me pulling my hair out for a while. Try:

BackColor='<%#System.Drawing.ColorTranslator.FromHtml(Eval(("ForecastColor") %>'
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,023
Latest member
websitedesig25

Latest Threads

Top