문제

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 request. 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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top