Solved

gridview Imagefield url

Posted on 2007-11-30
5
1,482 Views
Last Modified: 2010-10-05
I have an access database when I store images path ("Percorso") titles and descriptions

I am trying to display it with a gridview.

however I can get everything but the imagefield url in the codeview of my browser is empty

<td><a href="javascript:__doPostBack('ctl00$ContentPlaceHolder1$GridView1','Delete$0')">Delete</a></td><td>199</td><td>
<img src="" style="border-width:0px;" /></td>
<td>People</td>
<td>C:\Users\massimobrillante\Desktop\Websites\MarlonCommunications\public\photography\people\Fab110_05_06.jpg</td>
<td>no titolo</td><td>no descrizione</td><td>30/11/2007 0.00.00</td>

however the "Percorso" field (the path) that I am showing into the gridview for test is correctly filled  with the images URL. Below the gridview code as you can see from the above browser source code

why the image src is empty ?? when the server side code is displayed ??
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"

        DataKeyNames="PhotoId" DataSourceID="ObjectDataSourcePhotos">

        <Columns>

            <asp:CommandField ShowDeleteButton="True" />

            <asp:BoundField DataField="PhotoId" HeaderText="PhotoId" InsertVisible="False"

                ReadOnly="True" SortExpression="PhotoId" />

            <asp:ImageField DataImageUrlField="Percorso" HeaderText="Photo" />      

            <asp:BoundField DataField="Categoria" HeaderText="Categoria" SortExpression="Categoria" />

            <asp:BoundField DataField="Percorso" HeaderText="Percorso" SortExpression="Percorso" />

            <asp:BoundField DataField="Titolo" HeaderText="Titolo" SortExpression="Titolo" />

            <asp:BoundField DataField="Descrizione" HeaderText="Descrizione" SortExpression="Descrizione" />

            <asp:BoundField DataField="PhotoDate" HeaderText="PhotoDate" SortExpression="PhotoDate" />

        </Columns>

    </asp:GridView>

Open in new window

0
Comment
Question by:brillox
  • 2
  • 2
5 Comments
 
LVL 16

Accepted Solution

by:
anoyes earned 500 total points
ID: 20385826
If you look at the image path that is being produced, it's a local path (i.e. it's pointing to your C:\ drive).  This won't work on a website.  How is the path being stored in your database?  Is what is shown above (C:\Users\massimobrillante\Desktop\Websites\MarlonCommunications\public\photography\people\Fab110_05_06.jpg) the way it's stored in the DB?  The path that's in the database should be stored as a path that is relative to the root of your website.  So if you website www.website.com lives at C:\Users\massimobrillante\Desktop\Websites\MarlonCommunications\public\, then the path for the image stored in the DB should only be /photography/people/Fab110_05_06.jpg.  Note the "/" at the beginning - this tells the server that to start working from the root of the website.  Then your image (on the web) lives at www.website.com/photography/people/Fab110_05_06.jpg.  Does this make sense / solve your problem?
0
 

Author Comment

by:brillox
ID: 20386061
Yes you are right and I need a course in path :)

I am njow storing the image path as this ../imagepath and it works fine.
just to double check.. it will work also once online ? i guess it will.

0
 

Author Comment

by:brillox
ID: 20386074
I have the images stored in different subfolders as the owner of the website wnat to categorize all the images. so a path will be like http://www.mywebsite/public/category/image.jpg

so the http://www.mywebsite/public is always the same, is the path after this that changes

infact in the above post, ../imagepath is equal to
/public/category/imagename.extention
0
 
LVL 16

Expert Comment

by:anoyes
ID: 20386343
Yes it will work once posted online as well.  That's the great thing about relative paths.
0
 

Expert Comment

by:gbarje1
ID: 23534775
how can we display images if they are not stored within the working folder but on a totally different location on the server
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

25 Experts available now in Live!

Get 1:1 Help Now