Wrox Programmer Forums
Go Back   Wrox Programmer Forums > .NET > Other .NET > ADO.NET
ADO.NET For discussion about ADO.NET.  Topics such as question regarding the System.Data namespace are appropriate.  Questions specific to a particular application should be posted in a forum specific to the application .
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ADO.NET section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old October 21st, 2004, 06:42 PM
Registered User
Join Date: Oct 2004
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Bind image to the datagrid

I have a column Image in the table, data type varchar which hold the path to the actual image in my computer eg :- C:\Images\book.jpg.
When I try to display the result in the datagrid in web application it displays the path to me as C:\Images\book.jpg.
What I actually want is the actual picture instead of the full path.
I tried this code too:-
string img ="";
foreach(DataRow row in imageDataSet1.Tables["ImageTable"].Rows)
   img =row[0].ToString();
   //labISBN.Text = row[1].ToString();
   //labTitle.Text = row[2].ToString();
If I say Image1.ImageUrl = img;

I can get the image but not in the data grid
If I say DataGrid1.DataBind();//other code omitted
It displays the full path not the actual image in that column
I couldn’t find options in the property builder of the datagrid
I’m using C# as the programming language.
Please suggest me with few lines of code.
Thanks in advance,
Old October 31st, 2004, 09:44 AM
Friend of Wrox
Join Date: Jun 2003
Posts: 996
Thanks: 2
Thanked 11 Times in 11 Posts
Send a message via Yahoo to melvik

Dear friend: (Im back)
ensure u have created a Virtial Directory fot ur site so u should have that Addr. & for that u shoul dur
Keep in touch.

Hovik Melkomian.
Old October 31st, 2004, 05:00 PM
Imar's Avatar
Wrox Author
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts

I don't think this will work, Melvik. Server.MapPath works the other way around as it accepts a virtual path (like /Databases/Database.mdb) and will return a physical location like C:\MySite\Databases\Database.mdb)

learner_7983: You have a bit of a problem here; On your local machine, C:\Images\Image1.jpg will work, but not anywhere else.
To allow the browser to download a file, you'll need to reference it with a path that can be reached from within the site (e.g. /Images, like http://localhost/Images or www.YourServer.Com/Images

I think the easiest fix is to create a virtual folder under IIS called Images that points to C:\ImagesNext, in your databinding expression, take the full path and extract the file name. That is, make sure you get book.jpg from a path like C:\Images\book.jpg.

Then in your Image, set the path to:

ImageUrl = "/Images/" + imageFileName;

Alternatively, and better, store the root relative path in the database; just storing /Images/book.jpg or even book.jpg allows for a flexible setup.....


Imar Spaanjaars
Everyone is unique, except for me.
Old November 1st, 2004, 02:00 AM
Friend of Wrox
Join Date: Jun 2003
Posts: 996
Thanks: 2
Thanked 11 Times in 11 Posts
Send a message via Yahoo to melvik

But I thought he can not accecc the image location in localhost.

Hovik Melkomian.

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to Bind Data in DataGrid akumarp2p C# 2005 2 December 30th, 2006 12:11 PM
Datagrid Bind Problem param99 ASP.NET 1.0 and 1.1 Professional 1 November 23rd, 2006 12:34 PM
can we bind datagrid and dropdown list rakeshgv SQL Server 2000 0 August 21st, 2006 02:13 AM
bind a image filename stored in DB wth FORMSVIEW alexdcosta ASP.NET 2.0 Basics 0 June 22nd, 2006 05:30 AM
Bind datagrid to recordset MAntis_sg Classic ASP Databases 0 May 15th, 2006 07:31 AM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.