473,378 Members | 1,309 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Image binding

GD
I'm trying to bind (display) a SQL column to an <asp:image control. I was
under the impression that this could be achieved my pointing the ImageURL to
the databound column but it doesn't seem to work.

If I view the page source I can see that the ImageURL property has the value
'System.Byte[]' but no image is displayed.

By placing a STOP in the _ItemDatabound event I can see that the column does
contain data (DataBinder.Eval(e.Item.DataItem, "ThumbImage"))

Has anyone come across this before ?

Thanks

Gary
<asp:DataList id="ProductList" RepeatColumns="1" runat="server">
<ItemTemplate>
...
<asp:Image runat="server" id="imgPhoto" Visible="True"
ImageUrl='<%# DataBinder.Eval(Container.DataItem, "ThumbImage")%>'
width="100" height="100"></asp:Image>
...
</ItemTemplate>
</asp:DataList>
Dec 15 '06 #1
2 2791
You can't do it this way. You can't bind directly to a binary object from a
database. You need to have a seperate page generate the image that way the
browser will see it as an image file even though it is an asp.net page.
Usually this is done by passing in an ID as a querystring for the generator
page such as: imageGenerator.aspx?id=1. That page will then fetch the
particular image byte object from the database and dump it to the output
stream. In the page that calls it through an image element or asp:image
control it will be rendered as an image.
--

Hope this helps,
Mark Fitzpatrick
Former Microsoft FrontPage MVP 199?-2006

"GD" <No*****************************@eircom.net.NoSpam wrote in message
news:uE**************@TK2MSFTNGP06.phx.gbl...
I'm trying to bind (display) a SQL column to an <asp:image control. I was
under the impression that this could be achieved my pointing the ImageURL
to
the databound column but it doesn't seem to work.

If I view the page source I can see that the ImageURL property has the
value
'System.Byte[]' but no image is displayed.

By placing a STOP in the _ItemDatabound event I can see that the column
does
contain data (DataBinder.Eval(e.Item.DataItem, "ThumbImage"))

Has anyone come across this before ?

Thanks

Gary
<asp:DataList id="ProductList" RepeatColumns="1" runat="server">
<ItemTemplate>
...
<asp:Image runat="server" id="imgPhoto" Visible="True"
ImageUrl='<%# DataBinder.Eval(Container.DataItem, "ThumbImage")%>'
width="100" height="100"></asp:Image>
...
</ItemTemplate>
</asp:DataList>


Dec 15 '06 #2
GD
Thanks Mark

and for anyone else with the same problem .....

The getImage.aspx code is ...
Dim nPhotoId As Integer = CInt(Request.QueryString("PhotoId"))

Dim Dr As SqlClient.SqlDataReader = GetPhoto(nPhotoId) ' Open a connection
and run the stored proc that returns a photo

Response.Expires = 0

Response.Buffer = True

Response.Clear()

While Dr.Read

Response.BinaryWrite(Dr("Photo"))

End While

Response.End()

The binding code is

<asp:Image runat="server" id="imgPhoto" Visible="True" ImageUrl='<%#
"getImage.aspx?PhotoId=" & DataBinder.Eval(Container.DataItem,
"ThumbPhotoId")%>' width="80" height="80"></asp:Image>


"Mark Fitzpatrick" <ma******@fitzme.comwrote in message
news:Ox**************@TK2MSFTNGP03.phx.gbl...
You can't do it this way. You can't bind directly to a binary object from
a
database. You need to have a seperate page generate the image that way the
browser will see it as an image file even though it is an asp.net page.
Usually this is done by passing in an ID as a querystring for the
generator
page such as: imageGenerator.aspx?id=1. That page will then fetch the
particular image byte object from the database and dump it to the output
stream. In the page that calls it through an image element or asp:image
control it will be rendered as an image.
--

Hope this helps,
Mark Fitzpatrick
Former Microsoft FrontPage MVP 199?-2006

Dec 15 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Nate K | last post by:
I want to take an image stored in a SQL server and display it in a Datagrid. I think this can be done by registering an event in the binding that when it receives binary image data is sends it to...
2
by: gemel | last post by:
I have a set of images on a SQL2000 server that I use on a Windows Application by binding to a dataset. The controls on a Web Application require a URL. Is there a way that I can connect these...
1
by: Cade Carvell | last post by:
Hello, I have a class that I have a public property on it for an Image. In my class I change the image, different image etc. Anyway, Everythign works fine for the first image. I an bind the...
7
by: lgbjr | last post by:
Hello All, I¡¯m using a context menu associated with some pictureboxes to provide copy/paste functionality. Copying the image to the clipboard was easy. But pasting an image from the clipboard...
3
by: PaulJS | last post by:
Hi, I'm just getting started w/ VB.NET. I've been doing database development in MS Access, both as Access databases or as a front end for SQL Server. I need to create a VB.NET app to do some...
0
by: Deepak C.G via .NET 247 | last post by:
I want to dispose the image object in my child form, unless I won't dispose this object i can't delete the image file in my folder. I get this error in MDIparent form "An unhandled exception...
2
by: sanju | last post by:
Hi, I am struggling to replace a bit value 'True' or 'False' with a image true.gif or false.gif and bind it to a repeater control. I am getting values 'true' or 'false' depending on whether...
0
by: dlamar | last post by:
I'm using VB.NET with 2.0 - I have a number of PictureBoxes in my application - all of which use a context menu to change the associated Image to one of 5 options. I need to maintain the state of...
0
by: adubra | last post by:
Hi there, I am using a device context (DC) and a buffer to successfully draw to screen. However, when I update the DC at very high frame rate and drag the frame containing the image very quickly...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.