473,385 Members | 2,162 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,385 software developers and data experts.

Displaying images from a DB using a Repeater control.

Jim
I am trying to display images that are stored in a database, and I am using a
repeater control. What I still use the Response.BinaryWrite method with a
binding expression, if so, what with the code look like?
Nov 19 '05 #1
7 7553
Hi Jim,

Can it be so easy? Think I wrong now?

<ItemTemplate>
<asp:Image ID="myImage" Runat="Server" ImageUrl='<%#
Container.DataItem("myColumn") %>'/>
</ItemTemplate>

If I had wrong, want you create the Image or the ImageUrl in Code-Behind?
Nov 19 '05 #2
Hi Jim,

Can it be so easy? Think I wrong now?

<ItemTemplate>
<asp:Image ID="myImage" Runat="Server" ImageUrl='<%#
Container.DataItem("myColumn") %>'/>
</ItemTemplate>

If I had wrong, want you create the Image or the ImageUrl in Code-Behind?
Nov 19 '05 #3
Since you refer to the Response.BinaryWrite method it sounds like you have
your image stored as a BLOb/image/binary column in your db table, and not
simply a path to a jpg or gif in the file system.

If that's the case you need an aspx page that takes an image identifier as a
parameter, gets the BLOb column binary content from the db and delivers it
as the HTTP response using the Response.BinaryWrite method.

Your page also needs to add HTTP headers to tell the browser what kind of
content is coming, known as the "MIME Type", e.g. image/gif or image/jpeg.

In your repeater you add an image (<IMG ... />) with its souce set to the
name of your BLOb handler, and passing the image identifier as a parameter.

<ItemTemplate>
<asp:Image ID="myImage" Runat="Server"
ImageUrl='myBLObHandler.aspx?id=<%#
Container.DataItem("myImageIdentifier") %>' />
</ItemTemplate>

I've done this with all sorts of file content, MP3, Word, Excel, PDF, even
HTML, as well as gif, jpg and png images to avoid hassle over file system
resources and write permissions, etc.

"Jim" <Ji*@discussions.microsoft.com> wrote in message
news:BB**********************************@microsof t.com...
I am trying to display images that are stored in a database, and I am using
a
repeater control. What I still use the Response.BinaryWrite method with a
binding expression, if so, what with the code look like?

Nov 19 '05 #4
Since you refer to the Response.BinaryWrite method it sounds like you have
your image stored as a BLOb/image/binary column in your db table, and not
simply a path to a jpg or gif in the file system.

If that's the case you need an aspx page that takes an image identifier as a
parameter, gets the BLOb column binary content from the db and delivers it
as the HTTP response using the Response.BinaryWrite method.

Your page also needs to add HTTP headers to tell the browser what kind of
content is coming, known as the "MIME Type", e.g. image/gif or image/jpeg.

In your repeater you add an image (<IMG ... />) with its souce set to the
name of your BLOb handler, and passing the image identifier as a parameter.

<ItemTemplate>
<asp:Image ID="myImage" Runat="Server"
ImageUrl='myBLObHandler.aspx?id=<%#
Container.DataItem("myImageIdentifier") %>' />
</ItemTemplate>

I've done this with all sorts of file content, MP3, Word, Excel, PDF, even
HTML, as well as gif, jpg and png images to avoid hassle over file system
resources and write permissions, etc.

"Jim" <Ji*@discussions.microsoft.com> wrote in message
news:BB**********************************@microsof t.com...
I am trying to display images that are stored in a database, and I am using
a
repeater control. What I still use the Response.BinaryWrite method with a
binding expression, if so, what with the code look like?

Nov 19 '05 #5
Jim
Thanks Brian, but I am a little confused on how to use the
Response.BinaryWrite from the code behind when the method is called from the
repeater control. What would the method look like in the code behind?

Thanks for your help,
Jim

"Brian Lowe" wrote:
Since you refer to the Response.BinaryWrite method it sounds like you have
your image stored as a BLOb/image/binary column in your db table, and not
simply a path to a jpg or gif in the file system.

If that's the case you need an aspx page that takes an image identifier as a
parameter, gets the BLOb column binary content from the db and delivers it
as the HTTP response using the Response.BinaryWrite method.

Your page also needs to add HTTP headers to tell the browser what kind of
content is coming, known as the "MIME Type", e.g. image/gif or image/jpeg.

In your repeater you add an image (<IMG ... />) with its souce set to the
name of your BLOb handler, and passing the image identifier as a parameter.

<ItemTemplate>
<asp:Image ID="myImage" Runat="Server"
ImageUrl='myBLObHandler.aspx?id=<%#
Container.DataItem("myImageIdentifier") %>' />
</ItemTemplate>

I've done this with all sorts of file content, MP3, Word, Excel, PDF, even
HTML, as well as gif, jpg and png images to avoid hassle over file system
resources and write permissions, etc.

"Jim" <Ji*@discussions.microsoft.com> wrote in message
news:BB**********************************@microsof t.com...
I am trying to display images that are stored in a database, and I am using
a
repeater control. What I still use the Response.BinaryWrite method with a
binding expression, if so, what with the code look like?


Nov 19 '05 #6

"Jim" <Ji*@discussions.microsoft.com> wrote in message
news:FC**********************************@microsof t.com...
Thanks Brian, but I am a little confused on how to use the
Response.BinaryWrite from the code behind when the method is called from
the
repeater control. What would the method look like in the code behind?


Step back. There's no need to do it all in one page. In any web page the
HTML gets served in response to the first request for the URL and the
browser then makes further requests to collect any referenced resources,
like stylesheets, scripts, or images.

We're dealing with two separate aspx pages now.

You have one page, lets call it mainpage.aspx that includes a repeater that
includes repeated instances of the image...
<ItemTemplate>
<asp:Image ID="myImage" Runat="Server"
ImageUrl='myBLObHandler.aspx?id=<%#
Container.DataItem("myImageIdentifier") %>' />
</ItemTemplate>


The only code that gets called in this page is the databinding to get the
<img ... /> tag rendered once for each data row in the data source. This
results in:
<img src='myBLObHandler.aspx?id=1' />
<img src='myBLObHandler.aspx?id=2' />
<img src='myBLObHandler.aspx?id=...' />
<img src='myBLObHandler.aspx?id=n' />

This goes out as the normal text output to the response stream. The
receiving browser renders the HTML and picks up references to source files
for four images so makes requests back to your server for each image.

This is where the second file comes in.

You need an aspx page called myBLObHandler.aspx to handle the request.

This page has no HTML, its purely code behind.

The code takes the id given in the parameters, uses it to extract the
required binary content from the db, and then streams that binary content
back using Response.BinaryWrite()

Clear?

Brian Lowe
---------@
Nov 19 '05 #7
Jim
OK. I understand that and why it works. However, when I use the following
code that brings back the content type and image data from the database in a
data set it only displays a blank image with the dreaded red "x".

DataSet ds = new DataSet ();
ds =
objTest.RetrieveTestImage(Convert.ToInt32(Request. QueryString["id"]));
foreach (DataRow dr in ds.Tables [0].Rows) {
Response.ContentType= dr ["strType"].ToString();
Response.BinaryWrite((byte [])dr ["imgTestImage"]);
}

I know that there is data in all of my fields, because I printed them out as
a string in the browser except for the image data where I printed out the
length of the byte array. Any ideas?

"Brian Lowe" wrote:

"Jim" <Ji*@discussions.microsoft.com> wrote in message
news:FC**********************************@microsof t.com...
Thanks Brian, but I am a little confused on how to use the
Response.BinaryWrite from the code behind when the method is called from
the
repeater control. What would the method look like in the code behind?


Step back. There's no need to do it all in one page. In any web page the
HTML gets served in response to the first request for the URL and the
browser then makes further requests to collect any referenced resources,
like stylesheets, scripts, or images.

We're dealing with two separate aspx pages now.

You have one page, lets call it mainpage.aspx that includes a repeater that
includes repeated instances of the image...
<ItemTemplate>
<asp:Image ID="myImage" Runat="Server"
ImageUrl='myBLObHandler.aspx?id=<%#
Container.DataItem("myImageIdentifier") %>' />
</ItemTemplate>


The only code that gets called in this page is the databinding to get the
<img ... /> tag rendered once for each data row in the data source. This
results in:
<img src='myBLObHandler.aspx?id=1' />
<img src='myBLObHandler.aspx?id=2' />
<img src='myBLObHandler.aspx?id=...' />
<img src='myBLObHandler.aspx?id=n' />

This goes out as the normal text output to the response stream. The
receiving browser renders the HTML and picks up references to source files
for four images so makes requests back to your server for each image.

This is where the second file comes in.

You need an aspx page called myBLObHandler.aspx to handle the request.

This page has no HTML, its purely code behind.

The code takes the id given in the parameters, uses it to extract the
required binary content from the db, and then streams that binary content
back using Response.BinaryWrite()

Clear?

Brian Lowe
---------@

Nov 19 '05 #8

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

Similar topics

3
by: Dalan | last post by:
At first I was not certain what could cause Access 97 from displaying most jpeg images, but not all. After further testing, it seemed that all original images of less than 275 pixels per inch or...
2
by: marvin | last post by:
Hi, I am trying to display images in a repeater from a SQL database and do some transformations on the image prior to displaying them (such as thumbnail with a shadow). The problem is I can't...
0
by: Ryan Harvey | last post by:
Hi all, I have written a web user control that contains a repeater control. the ItemTemplate for this control is basically 6 Hyperlinks in a row, that are dynamically allocated one of 7 gif...
7
by: gemel | last post by:
I am developing an application that uses SQL 2000 as my source of images. I have successfully created the code to load the images onto the SQL Server and also to retrieve the images into a dataset....
5
by: Imran Aziz | last post by:
Hello all, I am populating the contents of a repeater control using a database query. In the repeater control I have a link , which I want to display or not based on the current logged in user....
5
by: Patrick.O.Ige | last post by:
I want to have a rollover image on an hyperlink inside a Repeater control but when i run the page i get "Image1 is undefined" Any ideas? I have a Hyperlink and an Image control in a repeater...
3
by: Charlie | last post by:
Hi: Is it possible to databind an image in Repeater Control? I see support for it in GridView, but not in Repeater control. There is another way to do this, but would rather go with new...
0
by: Nobody | last post by:
I'm working on an e-commerce type site where I have a bunch of categorized items... once you drill down to the items page, I show the list of items with a "preview picture". When you click on the...
1
by: Jeff | last post by:
hi asp.net 2.0 On my webpage I want to display a list of images. Most proparly display the list horizontal Sometimes I want only one image to be displayed and sometimes maybe 10 images....
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.