Forums

ASP

This topic is locked

Show default image if one doesnt exist

Posted 12 Dec 2005 15:38:12
1
has voted
12 Dec 2005 15:38:12 Steve Franzken posted:
Can someone please help me with the following:
I need to show a default image in the event that a dynamic image does not exist. I am using asp/vb dreamweaver.
The dynamic url to the image in dreamweaver is:
<img src="localhost/universal/photos/<%=(Recordset1.Fields.Item("MLS_NUMBER".Value)%>.1.jpg">
This works fine when an image exists.

But when an image does not exist, I want the page to show a default image which resides in my local images folder:
images/noimage.jpg

Now I began to write some ASP to do this but it doesnt work.
Can someone tell me what I am doing wrong?

<%
myPic="" & (Recordset1.Fields.Item("MLS_NUMBER".Value)
If Len(myPic) = 0 Then
myPic ="noimage.jpg"
Else
myPic=myPic & "1.jpg"
End If
%>
<img src="localhost/universal/photos/<%=myPic%>">

Thanks
Steve

Replies

Replied 13 Dec 2005 00:26:56
13 Dec 2005 00:26:56 Lee Diggins replied:
Hi Steve

Does the db send back a NULL value if no image name is stored in the field or an empty string, these are classed as different things and need to be checked for differently?

<%
Dim myPic

If IsNull(Recordset1.Fields.Item("MLS_NUMBER".Value) = True Then
myPic = 1.jpg
ElseIf (Recordset1.Fields.Item("MLS_NUMBER".Value) = "" Then
myPic = 1.jpg
Else
myPic = (Recordset1.Fields.Item("MLS_NUMBER".Value)
End If
%>

<img src="localhost/universal/photos/<%=myPic%>">

Sharing Knowledge Saves Valuable Time!!!
~ ~ ~ ~ ~ ~
<b>Lee Diggins</b> - <i>DMXzone Manager</i>
<font size="1">[ Studio MX/MX2004 | ASP -> VBScript/PerlScript/JavaScript | SQL | CSS ]</font>

Reply to this topic