Reputation: 673
I'm using an SQL query to gather information from a database and C# + ASP to get it in a table on the front end side. I'm trying to make it so that when I get an item, it will check its value and change the font color it is displayed in based on the value. I'm not sure how the syntax is supposed to work with all the tags so I'm getting weird results. So far it looks like:
<td nowrap valign="top">
if (<%# DataBinder.Eval(Container, "DataItem.StreetNumber")%> == "1") {
<font color = "red"><%# DataBinder.Eval(Container, "DataItem.StreetNumber")%></font>
}
else
<%# DataBinder.Eval(Container, "DataItem.StreetNumber")%></td>
Hopefully that makes some sense.
Upvotes: 1
Views: 1776
Reputation: 3563
Are you using the Repeater control? If so you can handle the ItemDataBound event and do what you like inside it - example
Upvotes: 0
Reputation: 3207
A simpler way to do it may be something like this:
<font color='<%# Int16.Parse(Eval("StreetNumber").ToString()) == "1" ? "red" : "black" %>' />
Upvotes: 2