RockStar
RockStar

Reputation: 87

How to use ImageUrl for displaying images in asp.net?

I'm trying to use an imagebutton inside a foreach loop. In order to access the path to my images, I need to pass an object to ImageUrl which contains the path to my images. I tried passing the guitar.image object but it is not displaying anything, only broken images. Please give solution on this problem. By the way, the reason why im using objects is because the path to my images is inside the database. Also i've already researched about Repeater and will use it in the future, but right now i wanted know if there is a solution without repeater.

<asp:Content ID='Content1' ContentPlaceHolderID='ContentPlaceHolder1' 
 Runat='Server'>


<% foreach (guitarBrand guitar in brandList) { %>
  <table class="one-third">
      <tr>
         <th rowspan="3" class="guitarLogoHover"><a href="<%= guitar.page 
 %>"><asp:ImageButton ID="Image" runat="server" ImageUrl="guitar.image" 
 Height="300px" Width="300px" /></a></th>
      </tr>
  </table>

 <% } %>

</asp:Content>

Upvotes: 1

Views: 7306

Answers (2)

Wouter van Vegchel
Wouter van Vegchel

Reputation: 469

The ImageUrl property will be translated to the src attribute. Make sure this path is a correct path to the specified file.

Upvotes: 0

James Exedy
James Exedy

Reputation: 31

Make sure your string in guitar.image is a proper path, relative or absolute.

ImageURL can be "images/image1.jpg" or "https://website.com/images/image1.jpg"

If you are using a relative path, keep in mind that adding a / to the front will have it start at the root of your site while having no / (like the example I gave above) will begin from your current page location.

Upvotes: 1

Related Questions