Reputation: 33
I am looking to evaluate two strings from my dataset to identify a class description using a ternary operator. I continue to get a compiler error when running this code stating that "Expression Expected". I think that it has to do with the comparison of strings but I have tried other comparison operators and can't seem to get it to work.
<ItemTemplate>
<tr>
<td><%# FormatDateTime(Eval("GameDate"), DateFormat.ShortDate)%></td>
<td class="<%# (Eval("Team1Score").ToString() > Eval("Team2Score").ToString()) ? 'Winner':'' %>"><%# Eval("Team1")%></td>
<td><%# Eval("Team1Score")%></td>
<td><%# Eval("Team2")%></td>
<td><%# Eval("Team2Score")%></td>
</tr>
</ItemTemplate>
Here is my sample data:
GameDate Team1 Team1Score Team2 Team2Score Winner
2012-04-14 Blues 5 Reds 3 Blues
2012-04-13 A's 4 B's 2 A's
2012-04-11 Blues 1 A's 1 Tie
2012-04-13 B's 3 Reds 2 B's
2012-04-10 Blues 7 B's 4 Blues
Thank you for your help
Upvotes: 2
Views: 14381
Reputation: 1
Try this
<%#Eval("Status").ToString()=="1" ? "ClubMember" : "Free User" %>
Upvotes: 0
Reputation: 2306
I think the problem is that you are trying to do comparison between two strings. Just convert the values to a int or something similar for comparison. So for example, change your comparison to something like the below:
<td class="<%# (Convert.ToInt32(Eval("Team1Score")) > Convert.ToInt32(Eval("Team2Score"))) ? 'Winner':'' %>"><%# Eval("Team1")%></td>
Or you can just cast it to the appropriate type:
<td class="<%# ((int)Eval("Team1Score") > (int)Eval("Team2Score")) ? 'Winner':'' %>"><%# Eval("Team1")%></td>
Hope this helps!
Upvotes: 8