Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 4 > ASP.NET 4 General Discussion
|
ASP.NET 4 General Discussion For ASP.NET 4 discussions not relating to a specific Wrox book
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 4 General Discussion section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 10th, 2011, 10:36 PM
Authorized User
 
Join Date: Aug 2011
Posts: 32
Thanks: 2
Thanked 0 Times in 0 Posts
Default How to display iamges using DataList control

Hi, I have a database which contains images (I entered these as Image). So, now I want to display these images using the DataList.

Using the GridView and DetailsView was pretty easy to display them (without any codes in the Code View), but I can't design them in the way I want to (I want to show the image to the lefts and the information about it to the right). I see the DataList is easier to put it that way, but instead of the image, it just displays the path (as in the database).

What is the best way to do this or what I'm doing wrong?
 
Old September 11th, 2011, 04:05 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi there,

Take a look at this artcle: http://imar.spaanjaars.com/414/stori...with-aspnet-20

Rather than displaying the image directly in the DataList you need to setup an Image control or img element and point it to a separate aspx page which renders the image from the database based on an id or path in the query string.

Hope this helps,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
 
Old September 13th, 2011, 03:36 PM
Authorized User
 
Join Date: Aug 2011
Posts: 32
Thanks: 2
Thanked 0 Times in 0 Posts
Default

Can I just change this:
<asp:Label ID="PhotoLabel" runat="server" Text='<%# Eval("Photo") %>' />
to something that displays the images instead of the path?. Since this information is being taken from a database according to client's selection (drop down menu)
 
Old September 13th, 2011, 03:44 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Not if "Photo" holds the byes for the picture. Images need to be requested separately by the browser and linked from the main HTML page using, for example, an <img /> element with its src attribute set. You can't embed the image directly into the main HTML of the page; that's just not how it works.

(Technically this isn't completely true; you could embed them with in-line images in CSS (http://www.websiteoptimization.com/s...inline-images/) but this only works well for tiny images such as icon files and has limited browser support).

But my article explains how to deal with this. Create a ViewImage.aspx file, use that in your DataList, pass the ID or the URL to the image in the query string and stream it from the ViewImage.aspx page as a separate request.

Hope this helps,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!





Similar Threads
Thread Thread Starter Forum Replies Last Post
datalist display almotions ASP.NET 2.0 Basics 1 February 18th, 2008 03:19 AM
How To Display Images in DataList abdul_owiusa General .NET 4 June 3rd, 2005 11:49 AM
How To Display Images in DataList abdul_owiusa General .NET 1 May 20th, 2005 09:01 AM
BMP Iamges shs BOOK: Beginning ASP.NET 1.0 1 August 31st, 2004 05:34 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.