How to display image and hyperlink in a DataList control?

Posted on 2006-04-11
Medium Priority
Last Modified: 2012-06-27
Hello - I've got to work up a page in ASP.NET 2.0 that displays logo images (about a dozen; 3 columns by 4 rows) with corresponding hyperlinks to the company websites

I've got these image file names and company website links in a user-maintained table (in a MS Access database), and I've set up a DataList control (with RepeatColumns="3") that pulls those two fields  

I don't see a particular control that displays an image with a hyperlink; is there one?

If there isn't one, then how do you set the "NavigateUrl" property of the HyperLink control from a field in the data source? "NavigateUrl="<%# Eval("CompanyURL") %>" doesn't work like I thought.


Question by:mlagrange
  • 3
  • 2
LVL 25

Expert Comment

ID: 16426922
Just add a template column like the following:

<asp:DataList ID="DataList1" runat="server">
                <a href='MyPage.aspx?ID<%#DataBinder.Eval(Container.DataItem,"ID_COLUMN")%>'><img src="image1.jpg" border=0></a>


Author Comment

ID: 16427379
Thanks nauman, that's half of it; the logo for each company needs to display along with their link.

How do I pull the file name into the <img src? I would think this would work:

     <img src='<%#Eval("CompanyLogo", "~/Images/{0}")%>' border=0>

but all I get are red x's

("CompanyLogo" is a field in the data source that holds the file name of the logo, and the logo's are in a folder called "Images")

Thanks again

LVL 25

Accepted Solution

nauman_ahmed earned 2000 total points
ID: 16429176
<img border=0 src='~images/<%#DataBinder.Eval(Container.DataItem,"CompanyLogo")%>'>


Author Comment

ID: 16430380
For some reason, "'~images/" didn't work; it wouldn't work until I put the full path in there

No matter; I've got a demo shortly, so I'm happy

Thanks, Nauman.
LVL 25

Expert Comment

ID: 16431000
Mark, Glad I was able to help :)


Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
Integration Management Part 2
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses
Course of the Month14 days, 9 hours left to enroll

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question