Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Setting BackColor of GridView cell to dynamic value 1

Status
Not open for further replies.

mrp9090

Programmer
May 22, 2006
71
GB
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?
 
Use the RowDataBound event instead and give each row a relevant CSS class.


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top