Si8 Si8 - 4 months ago 12
HTML Question

Why does Eval statement show the wrong image

SQL (

Active
column is of type
bit
):

id Question Active
1 Weather today 1


ASP.net
Eval
:

<img src='<%# Eval("Active") == "1" ? "images/active.png" : "images/inactive.png" %>' />


HTML:

<img src="images/inactive.png">


Why is the inactive.png image showing and not the active.

Answer

Bit fields correspond to boolean. Also you need to do a type conversion to ensure right comparison is done, as Eval outputs just object. So:

(bool)Eval("Active") == true