473,387 Members | 1,453 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,387 software developers and data experts.

DB Images to datagrid - how



Hi,

I want to load the images from my sqlserver200 db to the datagrid.I've
seen a code from odetocode.com and it recreated to my wish.

Database : Northwind;Table : from Employees , i want to take only
employeeid,photo to the grid.
html code for Datagrid..
<Columns>
<asp:BoundColumn DataField="employeeid"
HeaderText="EmployeeId"></asp:BoundColumn>
<asp:TemplateColumn HeaderText="Picture">
<ItemTemplate>
<img runat ="server" src ='<%# "WebGridPture.aspx?IDS=" +
DataBinder.Eval(Container.DataItem,"EmployeeId") %> ' ID ="Img1"/>
</ItemTemplate>
</asp:TemplateColumn></Columns>
</asp:datagrid></form>
------------------------------------pageload code------------------
database connection and grid fillings and the grid displays with the
empty images, quite natual since no byte conversion.But in a button a
've the following code to get the image to the grid.
--------------------button code-------------------------------------
string employeeid = Request.QueryString["IDS"].ToString(); //** object
ref not allowed to an instance of an object * error *//
Dr=cmd.ExecuteReader();
Dr.Read();
byte[] bytearray=(byte[]) Dr["photo"];
Response.BinaryWrite(bytearray);
---------------------------------
let us assume that the DBconnection is good.
I am bit confused , how the query string gets the value for all the
records. and where the datasource for the grid ,i also get the errors.

Could u please tell the mistake on these or if u provide a better code ,
it would be great .

Thanks in advance
Raghuraman

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 18 '05 #1
4 1376
The image data is served from an another file called WebGridPture.aspx which
accepts the photo Id as a query string (check the src tag of the <img> tag).
So, the code you have written for button will work if is put in a separate
file named webgridpture.aspx (probably in page load).

HTH.

"Raghu Raman" <ra************@rediffmail.com> wrote in message
news:eu**************@TK2MSFTNGP12.phx.gbl...
Hi,

I want to load the images from my sqlserver200 db to the datagrid.I've
seen a code from odetocode.com and it recreated to my wish.

Database : Northwind;Table : from Employees , i want to take only
employeeid,photo to the grid.
html code for Datagrid..
<Columns>
<asp:BoundColumn DataField="employeeid"
HeaderText="EmployeeId"></asp:BoundColumn>
<asp:TemplateColumn HeaderText="Picture">
<ItemTemplate>
<img runat ="server" src ='<%# "WebGridPture.aspx?IDS=" +
DataBinder.Eval(Container.DataItem,"EmployeeId") %> ' ID ="Img1"/>
</ItemTemplate>
</asp:TemplateColumn></Columns>
</asp:datagrid></form>
------------------------------------pageload code------------------
database connection and grid fillings and the grid displays with the
empty images, quite natual since no byte conversion.But in a button a
've the following code to get the image to the grid.
--------------------button code-------------------------------------
string employeeid = Request.QueryString["IDS"].ToString(); //** object
ref not allowed to an instance of an object * error *//
Dr=cmd.ExecuteReader();
Dr.Read();
byte[] bytearray=(byte[]) Dr["photo"];
Response.BinaryWrite(bytearray);
---------------------------------
let us assume that the DBconnection is good.
I am bit confused , how the query string gets the value for all the
records. and where the datasource for the grid ,i also get the errors.

Could u please tell the mistake on these or if u provide a better code ,
it would be great .

Thanks in advance
Raghuraman

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 18 '05 #2
Hi Shiva,

Thanks for that. That is right , the image tag src gets the query string
"IDS" for the photo , & it gets from the same paghe itself.

<img runat ="server" src ='<%# "WebGridPture.aspx?IDS=" +
DataBinder.Eval(Container.DataItem,"EmployeeId") %> ' ID ="Img1"/>
My doubt is , since i loaded the grid in the page load event, does the
<img src > tag get the query string for the every row in the grid.If it
is the case , how the following code works.Or shall i put the foll/
code in the page load event , so that it will go to the html tag for
every row.How ever the following code could be called only after the
grid's databind() method, am i right.Clear me , Please.
string employeeid = Request.QueryString["IDS"].ToString(); //** object
ref not allowed to an instance of an object * error *//
Dr=cmd.ExecuteReader();
Dr.Read();
byte[] bytearray=(byte[]) Dr["photo"];
Response.BinaryWrite(bytearray);
With thanks
Raghu

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 18 '05 #3
Hi,

Yes, for each row in the grid, the browser puts a request to
WebGridPture.aspx passing the employee id as IDS querystring value, in order
to render the image. This .aspx files in turn reads the image data from the
database using the IDS value passed on to it (via querystring).
As per the image tag's src attribute, this code which fetches the image has
to be in a separate file named WebGridPture.aspx. Having this code in the
same page as the grid will result in the error that you are getting now.

Hope this helps.

"Raghu Raman" <ra************@rediffmail.com> wrote in message
news:uI**************@TK2MSFTNGP12.phx.gbl...
Hi Shiva,

Thanks for that. That is right , the image tag src gets the query string
"IDS" for the photo , & it gets from the same paghe itself.

<img runat ="server" src ='<%# "WebGridPture.aspx?IDS=" +
DataBinder.Eval(Container.DataItem,"EmployeeId") %> ' ID ="Img1"/>
My doubt is , since i loaded the grid in the page load event, does the
<img src > tag get the query string for the every row in the grid.If it
is the case , how the following code works.Or shall i put the foll/
code in the page load event , so that it will go to the html tag for
every row.How ever the following code could be called only after the
grid's databind() method, am i right.Clear me , Please.
string employeeid = Request.QueryString["IDS"].ToString(); //** object
ref not allowed to an instance of an object * error *//
Dr=cmd.ExecuteReader();
Dr.Read();
byte[] bytearray=(byte[]) Dr["photo"];
Response.BinaryWrite(bytearray);
With thanks
Raghu

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 18 '05 #4


Thanks Shiva , I will try for it on other page
With Thanks
Raghu
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 18 '05 #5

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

Similar topics

2
by: Celine | last post by:
I am building a website using C#, asp.net and SqlServer. I need to store a lot of images in my database. I need to store thumbnails but also larger pictures(when user clicks thumbnails a larger...
3
by: | last post by:
Hi, I have a SQL Server database table where one of the columns is of type Image. The problem occurs when I try to retrieve images from the table. I'm using the following C# code: ...
2
by: John Do | last post by:
Hi, I want to store the path and the name of the images in a sql 2000 database and all the images in a folder named images. And then I want to display all the images in a datagrid. Does any one...
13
by: moondaddy | last post by:
Happy Holidays All! I want to load a datagrid with images and text (Image, text, image, text, etc...). The data for this datagrid will be coming from sql server and the images are stored as files...
9
by: tshad | last post by:
Is there a way to use your own image in place of the automatic one that ASP uses when doing editing in your DataGrid pages? We already have a style of button we are using and would like to be...
0
by: Tim::.. | last post by:
Please, please, please help!!! I have a datagrid that displays a list of contacts on our intranet site using the ActiveDirectory as it's main Data Source. I want to be able to show an image of...
9
by: Wayne Smith | last post by:
I've come up against a major headache that I can't seem to find a solution for but I'm sure there must be a workaround and I would really be grateful of any help. I'm currently building a web...
76
by: rcoco | last post by:
Hi all, I'm facing this problem I have images on my website but when I Deploye the website on server the Images are not there I only get the X sign. How can I go about this. Thanks
2
by: pozze | last post by:
Hi, I need to display images and other record information retrieved from an SQL 2005 database in a datagrid on a web page. I'm coding in VB .net I have recently changed over from VB ASP and i'm...
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:
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
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: 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...

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.