views:

22

answers:

1

I have some html which displays data from my database. Shown below is a line of code that shows if an item is enabled. What I would like to do is set its colour so that it is green when enabled and red when disabled. Can I add some javascript to this line to do this?

<asp:Label ID="ifmgr_ase_enabled" runat="server" Text="<%# DataAdapter.Enabled.ToString() %>" ClientIDMode="Static"/>
+1  A: 

You don't need to use javascript. You can do it during html generation like this:

Style="color:<%# DataAdapter.Enabled ? 'green' : 'red' %>"

just off the top of my head with no compilation guarantees :)

Polymorphix
Looks like it should work but at runtime no colour is applied :(
Retrocoder
How does the html tag look in the code after this was applied? Any obvious errors?
Polymorphix
No colour is applied to the text. The text is shown as if I hadn't added your code. No page errors are shown.
Retrocoder
I changed the "Style" part to the following which works. forecolor ="<%# DataAdapter.Enabled ? System.Drawing.Color.Green : System.Drawing.Color.Red %>". Needs the full path for the colours though.
Retrocoder
An even better solution :)
Polymorphix