Medula Oblongata
Medula Oblongata

Reputation: 53

Inline If Then Statement. ASP.NET

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

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

Upvotes: 3

Views: 3279

Answers (3)

ManoDestra
ManoDestra

Reputation: 6473

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.

Upvotes: 0

JanuszB
JanuszB

Reputation: 68

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.

Upvotes: 0

Andy
Andy

Reputation: 83

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"

Upvotes: 3

Related Questions