Link to home
Start Free TrialLog in
Avatar of dearness
dearnessFlag for American Samoa

asked on

What directory path do I use to display an image in a gridview for publishing.

I have tried what seems like 100 combinations of directory paths to display an image in a Gridview after publishing and I cant get any to work. The images show in development debugging mode but after publishing nothing. The path for the images comes from an Access database field, example....

~\Images\TICK.jpg

The published virtual directory is C:\MRO and the images are in folder C:\MRO\Images

I had a similar problem getting a document from a folder in code, server.mapPath(..
fixed that but this is different.
Avatar of dearness
dearness
Flag of American Samoa image

ASKER

Source code in developmet .....
<td>E10</td><td>SANDPAPER, NORTON 9&quot;&quot; X 11&quot;&quot; SHEETS 80GR</td><td>C-186*</td><td>177</td><td><img src="Images/TICK.jpg" /></td>

Source code after deployment.....
<td>E10</td><td>SANDPAPER, NORTON 9&quot;&quot; X 11&quot;&quot; SHEETS 80GR</td><td>C-186*</td><td>177</td><td><span></span></td>
If I set the NullImageUrl property in the datagridview column it displays correctly when published.

<asp:ImageField DataImageUrlField="PHOTO" HeaderText="PHOTO"
                NullImageUrl="~/Images/nopictureiconweb.gif">
            </asp:ImageField>
ASKER CERTIFIED SOLUTION
Avatar of Ajay Sharma
Ajay Sharma
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks for the reply,
this wont work in development or published.
I hope this extra information can help solve the problem.

I added another column and bound it to the same field in the database.

<asp:BoundField DataField="PHOTO" HeaderText="PHOTO" />
            <asp:ImageField DataImageUrlField="PHOTO" HeaderText="PHOTO"
                NullImageUrl="~/Images/nopictureiconweb.gif">
            </asp:ImageField>

In development I get the URL and picture showing, URL shows as  

~/Images/TICK.jpg

After publishing, the URL and picture will not show. For some reason that one database field is not being read, all other columns show correct database data.
A small break through with this. I am finding the web server is not displaying the latest data from the database, If I change data in the database columns the changed dont show in the browser. The server is displaying old information!. Since I added the photo column last after testing, it is not being read. IS there something I need to do at the server? I am Caching the data in an application object.

 Dim daDB As New dsMROTableAdapters.tblMROTableAdapter
        Dim dtDB As New System.Data.DataTable
        dtDB = daDB.selectFullDatabase
        'get the pm information from strongly typed data adapter  
        Application.Lock()
        Application("dtDatabase") = dtDB
        Application.UnLock()


Protected Sub btnMRO_Search_Click(sender As Object, e As System.EventArgs) Handles btnMRO_Search.Click
        Dim modifiedText As String
        Dim dtMRO As New DataTable
        dtMRO = Application("dtDatabase")
        'search for MRO number
        If txtMRO_Search.Text <> "" Then..................



I get the feeling this is where I am going wrong?
OK, I have just given myself a hard lesson on how using application caching while testing works. The cache is doing exactly what its is supposed to do.
Great, you did it yourself.

One point to can be noticed here that the ~ sign works only for the serverside controls not html controls.