PP:Displaying Default Images when required does not exist

P

prabhupr

Hi All

I have this requirement which I dont know how to (brain dead), may be
somebody can shed some light.

We have Photos (saved as JPG's) in file system, the naming convention
is <PhotoID>.jpg
where the PhotoID matches the ID in a SQL Database table column.

In the UI we used <img> tag to display this photo against each ID. The
requirement is, within UI, is there anyway I can check if that JPG
exists, and if it does not then use Default.jpg?

Something like

<img... photo25.jpg> OR <img... Default.jpg>
Thanks
PP
 
S

Saber

Hey,
You can use ExecuteScalar() to find the number of returned rows,
if executescalar returns 0 against "SELECT * FROM yourtable WHERE id=@id"
then
you can response.write("default.jpg") else response.write(id & ".jpg)
 
P

prabhupr

Hi Saber

I guess you mis-understood my question, sorry if I was not clear
enough. Here is the simple explanation...
I have the ProductID's in the database, say

ProductID ProductName
==================
1 XXX
2 YYY
3 ZZZ

In theory say, product 3 (ZZZ in this case) was created / added in the
databse as an item say today, so there is a chance that the image of
this product (ZZZ) is un-available till next week (some business
reasons). Once they have the image they will upload this image in file
system (not in database)

Now if the user browse the Product Catalog, I would like to show images
next to the Product, but as there is no image for Product3 (ZZZ), I
would like to show the "Default.jpg" image

If exists (<img... photo3.jpg>)
Show IT
Else
Show <img... Default.jpg>

Something like this.....

Hope I explained this better this time :)

Thanks
PP
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top