image in datalist please help

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
 
D

David Jessee

Server.MapPath returns a file path to the image. If you look that the
renderes html in you web page, you'll see that you end up with something
like "c:\inetpub\wwwroot\images\roomscenes\3245_ss.jpg"
you'll want to make sure that ou're returning a relative url to the image.

Also if you do a MapPath of "\images" then it maps the path from your web
root, as opposed to your web application's root (i.e. http://server/images
versus http://server/MyApp/images)


Side Note...
you can use a tilde "~" in urls with asp.net apps to denote your
appplication's root url, so you could use something like...

<asp:Image ImageUrl='<%#
"~\images\roomscenes\"+DataBinder.Eval(Container.DataItem,
"PartNo")+"_ss.jpg") %>' runat="server" ID="Image1" />

Assuming that "images" is a directory located inside your application (e.g.
http://server/myapp/images)

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 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
 

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