Click here to Skip to main content
15,899,313 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,

I am working on a e- commerce college project. In which i want to show list of all product in a category. for that i have decided that i will show image in a asp table cell. At runtime i am taking img src froc database and adding it to cell. text

C#
   c0.Text = "<img src=\"" + Convert.ToString(dvSql.Table.Rows[i][0]) + "\"/ ><br/>" + Convert.ToString(dvSql.Table.Rows[i][1]) + "<br/>" + Convert.ToString(dvSql.Table.Rows[i][2]) + "<br/>" + Convert.ToString(dvSql.Table.Rows[i][3]);
 row.Cells.Add(c0);
Table1.Rows.Add(row);


The string values are getting printed okay on the page, but no images are coming for img control. On checking source of webpage from the browser it shows correct values which is shown below.

HTML
<tr>
		<td><img src="D:\WebSite\Working code\Email.thebustles.com\Products\Apperal\images\perfume1.jpg"/ ><br/>Samsung Wave<br/>Samsung<br/>200</td>


please help me .. :( i am getting no clues
Posted

Hi,

Maybe this will help:
http://stackoverflow.com/questions/4090712/why-cant-i-do-img-src-c-localfile-jpg[^]

The image files have to be on your web server and then referenced by a url like:
HTML
<img src="www.mydomain.com/myimg.jpg" />

And you actually don't need to write the domain name. If the image is in the same folder as the web page you can write:
HTML
<img src="myimg.jpg" />


Regards
Joachim
 
Share this answer
 
v2
Comments
[no name] 6-Mar-12 15:09pm    
Hi Joachim,

I just used the 2nd option and it worked. :) Thanks a lot.
It was a real life Savior . :)
I don't think I've ever done a fully qualified physical location for an image source before... so I'm not sure it can be done.

What you probably need to do is give the image's position based on the page you are on in your project. Change the image element to use an relative path instead. For example (only for example) src="../../images/myimage", which tells the page it needs to go up two directories, then look in the images folder, then find myImage.

Start with an example and remove your data call for the src for now. Here is how I would find the relative path in my projects.

Page.ResolveUrl("~/Products/Apperal/Images/perfume1.jpg")

Assuming that your project's Url base is email.thebustles.com, this would yield: email.thebustles.com/Products/Apperal/Images/perfume1.jpg. Meaning this will allow you to not even worry about the relative path based on the page's location (which can be frustrating) and let the page figure it out for you. The tilda (~) means start with the root folder and work from there (only to asp.net).

Once that's working, then you can try to incorporate your datasource again. Of course, you'll have to change the database values to look like "~/Products/Apperal/Images/perfume1.jpg"
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900