I’ve been struggling to find some way to do my required conditional binding.
I want to use Eval("products_image") in conditional binding in such a way that if product_image exists in images directory then it’s ok, otherwise it should display “noimage.jpg”.
I tried to do it this way:
<%# (File.Exists(("ProductImages/"+Convert.ToString(Eval("products_image"))))) ? ("ProductImages/"+Convert.ToString(Eval("products_image"))) : "ProductImages/noimage_small.jpg" ; %>
I have tried other ways as well, but every time, I mess up with a bunch of errors.
Can anyone guide me the right way to do this?
Quite long and unreadable, isn’t it?
I’d suggest adding a method to your code behind or in a
<script>tagAnd then you’d simply use
Note that I’ve added a
Server.MapPathcall to the method so thatFile.Existswill actually look in the right place.