Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > How to Display an image, from a DB, into the Gridview (ASP.NET 2.0)

Reply
Thread Tools

How to Display an image, from a DB, into the Gridview (ASP.NET 2.0)

 
 
Auto
Guest
Posts: n/a
 
      04-28-2006
Please, let it alone...

"the4man" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) ups.com...
> That is still available in the final version of Vs 2005.
> http://msdn.microsoft.com/library/de...idViewEx06.asp
>



 
Reply With Quote
 
 
 
 
Auto
Guest
Posts: n/a
 
      04-28-2006
I have the binary image in my hand...
No, i need the following steps to get the same:

1) Reopen the DB
2) Run the query
3) Output the image
4) Close the DB.

Take it easy, please.


 
Reply With Quote
 
 
 
 
the4man
Guest
Posts: n/a
 
      04-28-2006
I'm trying to help you the best I can. I'm sorry, you were right. The
imgfield of gridviews are based in urls, not binary data. So is not
valid for you. Sorry again. Then, I think, the only way is doing what I
said: a template field with a dinamicly generated url. I use a similar
mechanism in one of the web sites to show images from DB (but with an
asp:Repeater instead of an asp:GridView). There is no problems to do
that with GridViews, as i said before. Every time you refresh the
gridview, the image will be reload. Just add a random parameter in the
url, to avoid that IE catch the image.

At this moment I don't see any other solution. That don't mean it
doesn't exists. If you need more help from me, please tell me. If not,
I will "let it alone" (I'm not very sure what that expresion means,
because I'm not native, but more or less...)

 
Reply With Quote
 
Auto
Guest
Posts: n/a
 
      04-29-2006
Thank you for your help.

What i was saying was that in the ASP.NET 2.0 beta version there was the
possibility to bind a binary image from a DB, directly to the gridview, or
using the URL. In the final version thay left only the URL mode. Please,
don't say it's the same or this is not true.
Also i told you, i refresh the gridview every one or two seconds.
If i have 30 rows already in the Dataset, i need to show them as soon as
possible.
It's not good, FOR EACH ROW

1) Reopen the DB
2) Do the query
3) Output the image
4) Close the DB

when i have ALREAY all the data i need (photo included) in the Dataset.

Since the images don't change, i thought to load them in the image fields of
the gridview - using the URL as you told me -only when the page loads, not
for the post back every one or two seconds. For each post back i'm going to
refresh the data of the gridview, but the photos.

Regards.

Auto.


 
Reply With Quote
 
J. Toop
Guest
Posts: n/a
 
      04-29-2006
The bandwidth between the dataset and the DB is usually of less concern than
the bandwidth between the dataset and the browser. They may be using diaup
or other slow connectivity methods.

How can the browser know what the bits are if it does not recieve MIME
information with the image. I thought that the browser had to know what the
bits were in order to interpret them for the user on the other end of the
browser.

This allows browsers to do stuff like, retrieve the text and slowly fill in
the images asynchronously and if the user decides to browse away in the
interim (before all of the images arrive) then that is his/her choice. The
server doesn't have to send the browser the files not requested. This would
save bandwidth.

The gridview is html/text (or something like that) so if you send the image
as part of that stream you could get some really cool bytes on the screen
but you are thinking that the browser knows that these bytes were a "png" or
a "jpg" or a "gif" or a "bmp" (or some other?). file that you uploaded into
a field.

Whenever I've stored images in a database I've had to store the "mime type"
in a field and the size in bytes (so the browser knows I've sent it all now
.... stop making the Netscape Icon animate).

Remember that you can only retrive images from SQL server (I don't think
that MSAccess can do this)

What about serving up "filename.doc" files. Then it all comes as one stream
and you don't have to worry about the complexities of writing an "url" into
an <IMG> tag or other active content issues.

JT

"Auto" <(E-Mail Removed)> wrote in message
news:OV$(E-Mail Removed)...
> Thank you for your help.
>
> What i was saying was that in the ASP.NET 2.0 beta version there was the
> possibility to bind a binary image from a DB, directly to the gridview, or
> using the URL. In the final version thay left only the URL mode. Please,
> don't say it's the same or this is not true.
> Also i told you, i refresh the gridview every one or two seconds.
> If i have 30 rows already in the Dataset, i need to show them as soon as
> possible.
> It's not good, FOR EACH ROW
>
> 1) Reopen the DB
> 2) Do the query
> 3) Output the image
> 4) Close the DB
>
> when i have ALREAY all the data i need (photo included) in the Dataset.
>
> Since the images don't change, i thought to load them in the image fields
> of the gridview - using the URL as you told me -only when the page loads,
> not for the post back every one or two seconds. For each post back i'm
> going to refresh the data of the gridview, but the photos.
>
> Regards.
>
> Auto.
>
>



 
Reply With Quote
 
the4man
Guest
Posts: n/a
 
      04-30-2006
Ok, I understand you. I said that was "the same" because I red the
article very quickly. It was one of that times that you see something
clear....even when is not true. . But yes, you are right, that option
doesn't exists in the final versión.

If you want to show the images just in page load, not in every refresh,
to reduce database access, try with my method again.....but WITHOUT the
"random" parameter. The browser will cache the images so won't have
calls to the DB (because won't call the createimage.aspx page). And you
can use server cache too. The page which generate the images can be
cached in server, just add an OutPutCache directive with a varybyparam
option. This will reduce access to the DB, and it always works (the
browser cache can be disabled by users). Another tip: add to the URL
the image width and height. For example:

<img src="createimage.aspx?image=10" width="100" height="60" />

With theese data the browse can "reserve" space in the page for the
images, and will show the texts as soon as posible, even if the images
aren't download yet.

I hope this help you.

By the way: yes, it's possible to retrive images from a MSAccess DB.

 
Reply With Quote
 
Auto
Guest
Posts: n/a
 
      04-30-2006

"J. Toop" <(E-Mail Removed)> wrote in message
news:uI%23SDV%(E-Mail Removed)...
> The bandwidth between the dataset and the DB is usually of less concern
> than the bandwidth between the dataset and the browser. They may be using
> diaup or other slow connectivity methods.


OK.
Anyway the image must arrive to the browser, isn't it ?

> How can the browser know what the bits are if it does not recieve MIME
> information with the image. I thought that the browser had to know what
> the bits were in order to interpret them for the user on the other end of
> the browser.


OK, good point.
I thought the imagefield was so smart to look at the header of the image
stream (binary in the DB) to understend what kind of images it was.


> This allows browsers to do stuff like, retrieve the text and slowly fill
> in the images asynchronously and if the user decides to browse away in the
> interim (before all of the images arrive) then that is his/her choice. The
> server doesn't have to send the browser the files not requested. This
> would save bandwidth.


OK, good point.


> The gridview is html/text (or something like that) so if you send the
> image as part of that stream you could get some really cool bytes on the
> screen but you are thinking that the browser knows that these bytes were a
> "png" or a "jpg" or a "gif" or a "bmp" (or some other?). file that you
> uploaded into a field.


Yes, i hope so, but maybe i'm realizing it is not.


> Whenever I've stored images in a database I've had to store the "mime
> type" in a field and the size in bytes (so the browser knows I've sent it
> all now ... stop making the Netscape Icon animate).


The size in byte could be known from the DB Field.
I worked with SQL Server and DB with Images.
I was able to know the size by the DB field they were stored,
and also i was able to show them feeding the leadtools control.


> Remember that you can only retrive images from SQL server (I don't think
> that MSAccess can do this)


I think yes, i have a sample it does.

------------------------------------------------
string idx;

idx = Request.QueryString["idx"];
if (idx == null)
idx = "1";

OleDbConnection myConn = new
OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" +
Server.MapPath("App_Data\\Photos.mdb"));
myConn.Open();
OleDbCommand _OleCmd = new OleDbCommand("SELECT * FROM Tabella1 WHERE ID = "
+ idx, myConn);
OleDbDataReader dr = _OleCmd.ExecuteReader();
if (dr.Read())
{
Response.Clear();
Response.ClearContent();
Response.ContentType = dr["ContentType"].ToString();
Response.BinaryWrite((byte[])dr["Photo"]);
}
else
Response.Write("NOT FOUND!");

if (myConn.State != System.Data.ConnectionState.Closed)
myConn.Close();
------------------------------------------------

The access db has stored also the content type.


> What about serving up "filename.doc" files. Then it all comes as one
> stream and you don't have to worry about the complexities of writing an
> "url" into an <IMG> tag or other active content issues.


How can i get a .doc file form an image stored in a DB ?
I can try for learning purpose, but i don't think this is usefull for my
monitoring application.

Thank you.

Auto.



 
Reply With Quote
 
Auto
Guest
Posts: n/a
 
      04-30-2006
I had a smart idea

I can do this query in order to get the URL of the Image directly from the
DB:

"SELECT *, 'ShowPhoto.aspx?idx=' + cast(EmployeeID AS nvarchar(7)) AS
PhotoURL FROM Employees"

and bind it to an image field in the gridview as shown in the article in my
first post.
Anyway, How can i know which ContentType the photo has ?

In the Northwind DB the emplyee's photo is a BMP, but i if i set the
ContentType of the page = "image/bmp", i don't see any photo.
I tried with a different DB that has jpg photo and it works.

So, any help with emplyee's photo in the northwind DB ?



 
Reply With Quote
 
the4man
Guest
Posts: n/a
 
      04-30-2006
The content type is correct. I don't know why the image is not showed.
I will do some test when I arrive at work on monday. At this moment I
don't have the northwind db available.

Bye!

P.S: very good idea!

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How can i display blob into GridView André Despont ASP .Net Datagrid Control 0 12-21-2006 05:46 PM
How to Display an image, from a DB, into the Gridview (ASP.NET 2.0) Auto ASP .Net Datagrid Control 1 05-26-2006 01:01 PM
GridView Hierarchical View - Gridview in Gridview =?Utf-8?B?bWdvbnphbGVzMw==?= ASP .Net 1 05-09-2006 06:48 PM
How to Display an image, from a DB, into the Gridview (ASP.NET 2.0) Auto ASP .Net Building Controls 2 04-30-2006 10:42 AM
How to Display an image, from a DB, into the Gridview (ASP.NET 2.0) Auto ASP .Net 1 04-27-2006 08:38 AM



Advertisments