How to use an image in sql in an unbound datalist

A

Aussie Rules

Hi,

I have a datalist on my page that I bind a dataset to in my code..

SqlDataAdapter.SelectCommand = SqlCommand
SqlDataAdapter.Fill(ds, "SearchResults")

DataList1.DataSource = ds
DataList1.DataBind()



One of my cols in my dataset is a sql image col, that contains a small
image. I want to display the image in the datalist. I have placed a HTML
image (serverside) in my datalist item template.

For the other cols which are text I simply have set the datalist to display
the values using <%#Container.DataItem("bedrooms")%> in the HTML.

How can I do this for an image.

Thanks
 
W

Walter Wang [MSFT]

Hi Aussie,

This is a very common scenario. Basically you can create a separate WebForm
to accept a parameter on the QueryString to designate which image you need,
in its Page_Load, simply read from the database and write out the binary
data with appropriate content-type:

#How To Write Binary Files to the Browser Using ASP.NET and Visual C# .NET
http://support.microsoft.com/kb/306654

Then in your main WebForm has the DataList, in the <asp:Image element, set
its image url to the previous WebForm with the image id parameter in
QueryString.

Please let me know if you need a working example on this.


Regards,
Walter Wang ([email protected], remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
 
A

Aussie Rules

Hi,

Thanks for your reply, but not sure I understand fully.

There could be hundreds of images being used by the datalist, as each item
in the datalist is different. The datalist is showing items in a catalog,
and each item of course is different with its own photo.

I looked at you kb link, but I really only know vb.net so was a bit lost
with it. If you have something in VB that would be great.

Thank for you assistance.

Thanks
 
W

Walter Wang [MSFT]

Hi Aussie,

When setting the image url, you can pass a querystring parameter to the
webform so that it will know which image to return:

Function FormatURL(strArgument) as String
Return ("readrealimage.aspx?id=" & strArgument)
End Function


Here's an example in VB.NET:


#retriving image from database in C#, VB.NET, ASP.NET
http://www.dotnetspider.com/qa/Question33427.aspx



Regards,
Walter Wang ([email protected], remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,226
Members
46,816
Latest member
nipsseyhussle

Latest Threads

Top