By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,017 Members | 1,169 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,017 IT Pros & Developers. It's quick & easy.

How to use an image in sql in an unbound datalist

P: n/a
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

Sep 25 '07 #1
Share this Question
Share on Google+
3 Replies


P: n/a
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 (wa****@online.microsoft.com, 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.

Sep 26 '07 #2

P: n/a
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

""Walter Wang [MSFT]"" <wa****@online.microsoft.comwrote in message
news:$K**************@TK2MSFTNGHUB02.phx.gbl...
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 (wa****@online.microsoft.com, 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.
Sep 28 '07 #3

P: n/a
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 (wa****@online.microsoft.com, 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.

Sep 28 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.