1

I want to change the forecolor of a label in .aspx I tried to compare if value is > 0 then it should be Green if not then Red

the problem is in condition part I tried to use int, double, float.. but non is working I always get Specified cast is not valid.

This is my line

<asp:Label ID="TAmtLabel" runat="server" Text='<%# Eval("TAmt", "{0:c}") %>' Font-Size="13pt" Font-Bold="true" ForeColor='<%# (int)Eval("TAmt") > 0 ? "#00C000" : "#C00000" %>' />
Ken
  • 295
  • 1
  • 6
  • 18

1 Answers1

0

Here's my approach, and hope helps :)

Instead of the ForeColor, I used the CssClass..

<asp:Label ID="TAmtLabel" runat="server" Text='<%# Eval("TAmt", "{0:c}") %>' Font-Size="13pt" Font-Bold="true" CssClass='<%# Convert.ToDouble(Eval("TAmt")) > 0 ? "less" : "more" %>' />

and implement something like this in your css

<style type="text/css">
    .less
    {
        color : #00C000;
    }
    .more
    {
        color : #C00000;
    }
</style>

converting the html colors are as complicated as this topic as it is..convert hex code to color name

Community
  • 1
  • 1
ken lacoste
  • 894
  • 8
  • 22