简体   繁体   中英

Hyperlink display image in ASP.NET Datalist

I am trying to get an image to display on a page using a Hyperlink inside a datalist.However, the image will not display, I just get the correct number of boxes with what I call the no image picture. I know that it is retrieving the filepath correctly. The tooltip shows the correct path, it is the exact path going into a repeater that works, but does not display the image. Any help would be greatly appreciated.

<%@ Control Language="C#" AutoEventWireup="true" CodeFile="HomePagePhotosList.ascx.cs"     Inherits="UserControls_HomePagePhotosList" %>
<asp:DataList ID="list" runat="server" Width="1000px" CssClass="EventsList" 
    RepeatDirection="Horizontal">
   <HeaderStyle CssClass="DepartmentsListHead" />
   <HeaderTemplate>
   </HeaderTemplate>  
   <ItemTemplate>
   <asp:HyperLink 
      ID="HyperLink1" 
      Runat="server" 
      ImageUrl='<%#System.String.Format("Images/{0}", DataBinder.Eval(Container.DataItem, "Filepath")) %>'
      NavigateUrl='<%# Link.ToEditMinutesAdmin(Eval("ImageID").ToString())%>'
      ToolTip='<%# System.String.Format("Images/{0}", DataBinder.Eval(Container.DataItem, "Filepath")) %>'>
   </asp:HyperLink>
   </ItemTemplate>
</asp:DataList>

In order to fix this problem I had to change the

ImageUrl='<%#System.String.Format("Images/{0}", DataBinder.Eval(Container.DataItem, "Filepath")) %>' 

To

      ImageUrl='<%#System.String.Format("~/Images/{0}", DataBinder.Eval(Container.DataItem, "Filepath")) %>' 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM