Categories: MSDN / DotNet / Java / Scripts / Linux / PHP Ask - La ask - La Answer

alternative image

Hi there

I'm developing an application that returns database records along with an associated image. Not all of the records have associated images however, and in cases like these I'd like to serve up a default "sorry we don't have your image".jpg instead. There are no associated database fields that indicate whether an image is present or not - I have to establish the presence of the .jpg at run time and then display either that file, or default.jpg.

I tried using the ALT property but that just serves up text. Does anyone know how I might go about serving up this default.jpg file? :confused:

Many thanks - Dave
[661 byte] By [DaveMere] at [2007-11-11 7:18:37]
# 1 Re: alternative image
Hi Dave,

If you use an imagecontrol, you can define the alternative image in the onerror.
something like this :
<IMG ID="Image" Height="89px" src='<% "dir\" & Eval("fieldname", "{0}") & ".jpg" %>' Width="52px" border=0 onerror="this.src='../images/default.gif';"/>
I used this with a datalist.
:)

But I dont get it to work with a asp:image. Did you find a workaround ?

Leon
LeonW at 2007-11-11 17:27:14 >