开发者

Conditional statement in databound expression

开发者 https://www.devze.com 2023-01-28 15:07 出处:网络
I want to display an image if 2 conditions are met. The data item is not null The value of the data item is greater than 0

I want to display an image if 2 conditions are met.

  1. The data item is not null
  2. The value of the data item is greater than 0

Markup

<img id="Img1" runat="server" visible='<%#IIF( DataBinder.Eval(Container.DataItem,    
"amount") is DBNull.Value Or DataBinder.Eval(Container.DataItem, 
"amount") = 0, False, True)%>' src="/Images/check.png" />

Error message

Operator '=' is not defined for type 'DBNull' and type 'Integer'. Description: An unhandled exception occurred during the execution of the current web requ开发者_运维问答est. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.InvalidCastException: Operator '=' is not defined for type 'DBNull' and type 'Integer'.


Try using OrElse. In VB.Net the Or conditional operator causes both sides to evaluate regardless of the success. So if you have a null it's going to attempt the comparison anyway. Using OrElse will cause the second condition not to be evaluated if the first is true.

0

精彩评论

暂无评论...
验证码 换一张
取 消