3

I need to make a statement much like

<%#((bool)Eval("inactive")) ? "<span style='color:red;font-weight:600;'>INACTIVE</span>" : "<span style='color:green;font-weight:600;'>ACTIVE</span>"%>  

Except instead of a boolean I need it to take 3 Conditional Statements.

So using

<%#Eval("Program_Num") %>  

I need it to say

  • If Program_Num == 1 then it's X,
  • if Program_Num == 2 then it's y,
  • if Program_Num == 3 then it's z;

I'll clarify and answer any questions to the best of my abilities, thank you for the help.

2
  • May not be as clean, but are <% if { %> <% } else if { %> blocks out of the question? Commented Mar 15, 2016 at 19:30
  • No. All answers are appreciated. Commented Mar 15, 2016 at 19:32

3 Answers 3

3

Try something like this.

<%# (int)Eval("Program_Num") == 1 ? "X" : (int)Eval("Program_Num") == 2 ? "Y" : (int)Eval("Program_Num") == 3 ? "Z" : "default value" %>

It's like saying this.

if ((int)Eval("Program_Num") == 1)
    "X"
else if ((int)Eval("Program_Num") == 2)
    "Y"
else if ((int)Eval("Program_Num") == 3)
    "Z"
else
    "default value"
Sign up to request clarification or add additional context in comments.

1 Comment

I'm glad you like my answer ^_^
0

You can try the following:

<%#Eval("Program_Num") == 1 ? "X" : Eval("Program_Num") == 2 ? "y" : Eval("Program_Num") == 3 ? "z" %> 

Obviously you need to substitute "x" "y" "z" with whatever you want it display.

Comments

0

It's inelegant, but you could just use a nested version of it:

var x = Program_Num == 1 ? "X" : (Program_Num == 2 ? "x" : (Program_Num == 3 ? "y" : "DEFAULT"))

I've kept it as clean C# for clarity here. You can adapt it for ASP.NET.

If you're going to three levels, then it's really time to start using proper if or switch constructs though.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.