简体   繁体   English

Team Foundation ASP.NET(如果条件)

[英]Team Foundation ASP.NET if Condition

I'm working on TFS. 我正在TFS上工作。 My question is how can I use if condition in Default.aspx? 我的问题是如何在Default.aspx中使用条件?

This is my code: 这是我的代码:

<%#DataBinder.Eval(Container.DataItem, "Fields['Severity'].Value")%>

When I try 当我尝试

<%!String.IsNullOrEmpty(DataBinder.Eval(
    Container.DataItem, "Fields['Severity'].Value").ToString()) ? "a" : "b";%>

it is not working. 它不起作用。 How can I fix it if 如果我该如何解决

<%#DataBinder.Eval(Container.DataItem, "Fields['Severity'].Value")%>

is empty value will be " ". 为空值将为“”。 If workitemtype is Change the request severity will be empty, if workitemtype is Bug - severity can be Medium Critical low. 如果workitemtype为Change,则请求严重性为空;如果workitemtype为Bug-严重性为Medium Critical low。

Your conditional operator is correct, you don't need a terminating semi-colon(;) at the last though. 您的条件运算符是正确的,尽管最后您不需要终止分号(;)。 This should work:- 这应该工作:

'<%# !String.IsNullOrEmpty(DataBinder.Eval(Container.DataItem,
                 "Fields['Severity'].Value").ToString()) ? "a" : "b" %>'

Update: 更新:

Your new exception might be occurringbecause ToString() will throw a null reference exception if the value is null . 您的新异常可能正在发生,因为如果值nullToString()会引发空引用异常。 You can type-cast it to avoid this:- 您可以键入它来避免这种情况:-

'<%# String.IsNullOrEmpty((string)DataBinder.Eval(Container.DataItem,
           "Fields['Severity'].Value")) ? String.Empty : 
            DataBinder.Eval(Container.DataItem,"Fields['Severity'].Value").ToString() %>' 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM