[英]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.除了不是布尔值,我需要它接受 3 个条件语句。
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.我会尽我所能澄清和回答任何问题,谢谢你的帮助。
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"
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.显然,您需要将“x”“y”“z”替换为您想要显示的任何内容。
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.为了清楚起见,我将其保留为干净的 C#。 You can adapt it for ASP.NET.
您可以针对 ASP.NET 对其进行调整。
If you're going to three levels, then it's really time to start using proper if or switch constructs though.如果您要进入三个级别,那么现在是开始使用正确的 if 或 switch 结构的时候了。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.