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
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.
精彩评论