image in datalist

M

mahsa

hi
I have a datalist that show product and their image I us
<asp:Image ImageUrl='<%#Server.MapPath(@"\images\roomscenes\"+DataBinder.Eval(Container.DataItem, "PartNo")+"_ss.jpg") %>' runat="server" ID="Image1" /
but some times there is no image for one product and the page show me the asp image whitout any picture with a red
i what if there is no picture for one product the datalist dont show any thing and dont show asp:image whitout picture ,do you have any ide
 
M

mahsa

hi I can use the code for show the image I have imajin i have 30 products that 28 of them have image but 2 of them dosent have when I try to show the image in datalist for 2 product that dont have image datalist show imagebutton whithout any image with redx I want to do something that if the product dont have image the datalist dosent show image button
 
M

Marcelo Dabanovich Lavio

Hi Mahsa,

You may try this:

<asp:Image
ImageUrl='<%#Server.MapPath(@"\images\roomscenes\"+DataBinder.Eval(Container
..DataItem, "PartNo")+"_ss.jpg") %>' Visible='<%#
System.IO.File.Exists(@"\images\roomscenes\"+DataBinder.Eval(Container.DataI
tem, "PartNo")+"_ss.jpg") %>' runat="server" ID="Image1" />


HTH,
Marcelo


mahsa said:
hi,
I have a datalist that show product and their image I use
<asp:Image
ImageUrl='<%#Server.MapPath(@"\images\roomscenes\"+DataBinder.Eval(Container
..DataItem, "PartNo")+"_ss.jpg") %>' runat="server" ID="Image1" />
but some times there is no image for one product and the page show me the
asp image whitout any picture with a red X
i what if there is no picture for one product the datalist dont show any
thing and dont show asp:image whitout picture ,do you have any idea
 
M

mahsa

hi I use th
<asp:Imag
ImageUrl='<%#Server.MapPath(@"\images\roomscenes\"+DataBinder.Eval(Container.DataItem, "PartNo")+"_ss.jpg") %>' Visible='<%#!System.IO.File.Exists(@"\images\roomscenes\"+DataBinder.Eval(Container.DataItem, "PartNo")+"_ss.jpg") %>' runat="server" ID="Image1" /
but it always return visible=fals
when i use
FileInfo fi = new FileInfo(Server.MapPath(@"\images\roomscenes\"+strFileName+"_ss.jpg"))
if (fi.Exists
{do some thing
it shows the currect answer how can I use it in image tag?
 
M

Marcelo Dabanovich Lavio

Hi Masha,

I'm sorry, but the Server.MapPath call is missing in my sample. The correct
value for the Visible attribute should be

<%#
!System.IO.File.Exists(Server.MapPath(@"\images\roomscenes\"+DataBinder.Eval
(Container.DataItem, "PartNo")+"_ss.jpg")) %>

because the system will net to check for the existence the acual file (on
the physical path, and not the virtual one).

HTH,
Marcelo




mahsa said:
hi I use the
<asp:Image
ImageUrl='<%#Server.MapPath(@"\images\roomscenes\"+DataBinder.Eval(Container
..DataItem, "PartNo")+"_ss.jpg") %>'
Visible='<%#!System.IO.File.Exists(@"\images\roomscenes\"+DataBinder.Eval(Co
ntainer.DataItem, "PartNo")+"_ss.jpg") %>' runat="server" ID="Image1" />
 
M

Marcelo Dabanovich Lavio

Wrong again... : - (


this shall work:
Visible='<%#
System.IO.File.Exists(Server.MapPath(@"\images\roomscenes\"+DataBinder.Eval(
Container.DataItem, "PartNo")+"_ss.jpg")) %>'
 
V

Vidar Petursson

Hi,

One way would be:

<img onerror="fixIt(this)".....

function fixIt(oImg){
oImg.src = "PATH/DEFAULTIMG.gif";
}

If browser has an error loading an image it will use the DEFAULTIMG.gif
just be sure
that the default image is there else endless loop problems :)

--
Best Regards
Vidar Petursson
==============================
Microsoft Visual: Scripting MVP 2000-2004
http://www.icysoft.com/
http://www.deus-x.com/ Instant e-commerce
http://www.microsoft.com/technet/scriptcenter/
Playground: http://213.190.104.211/ ( IE 5.5+ only )

No matter where you go there you are
==============================
 

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,982
Messages
2,570,185
Members
46,736
Latest member
AdolphBig6

Latest Threads

Top