How to use a ASP.NET Eval() function in a ternary operator?

后端 未结 2 1038
南笙
南笙 2021-01-22 03:41

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

相关标签:
2条回答
  • 2021-01-22 04:08

    Try this

    <%#Eval("Status").ToString()=="1" ? "ClubMember" : "Free User" %>
    
    0 讨论(0)
  • 2021-01-22 04:28

    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!

    0 讨论(0)
提交回复
热议问题