+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / How to replace images when using Repeater - Eval("Content")

How to replace images when using Repeater - Eval("Content")

4 posts, 0 answered
  1. HarryS
    HarryS avatar
    4 posts
    Registered:
    01 Nov 2006
    12 Oct 2010
    Link to this post
    Hi,

    I am using a Repeater to list blog Content as per the below:

    01.<asp:Repeater runat="server" ID="blogPostsRepeater">
    02.<ItemTemplate>
    03.<div class="countClass" style="margin-bottom:90px;">
    04.      <b><asp:Label runat="server"  ID="PostTitle" Text='<%# Eval("Title") %>'></asp:Label></b>
    05.      <br />
    06.      <asp:Label runat="server"  ID="Label2"  Text='<%# Eval("Publication_Date") %>' ></asp:Label>
    07.      <br />
    08.      <asp:Label runat="server"  ID="Label3"  Text='<%# Eval("Category") %>' ></asp:Label>
    09.      <br />
    10.      <asp:Label runat="server"  ID="Content"  Text='<%# Eval("Author") %>' ></asp:Label>
    11.      <asp:Image runat="server" ID="AuthorPic" ImageUrl='<%# Eval("Author", "/App_Themes/DwTheme/Images/avatars/{0}.png")%>' />
    12.      <br /><br />
    13.      <asp:Literal runat="server" ID="litContent" Text='<%# Eval("Content") %>'></asp:Literal>
    14.      <br /><br />
    15. 
    16.</div>
    17.</ItemTemplate>
    18.</asp:Repeater>

    As part of the <%# Eval("Content") %>. how do I get the images to show?
    At the moment it renders as:
    <img alt="Alt Text for image" src="[Libraries]f6ea22ac-4fd6-40e9-b7ec-ffeaa02fb1c8">

    Is there are an easy way to change the src of the image to show the correct image?

    Thanks,
    Harry



  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    12 Oct 2010
    Link to this post
    Hi HarryS,

    You need to resolve the dynamic url "[Libraries]f6ea22ac-4fd6-40e9-b7ec-ffeaa02fb1c8 before setting the ImageUrl. You can do this inside ItemDataBound control and set the ImageUrl for each DataItem which is IContent object.
    Another option is creating another class or interface where you have the url resolved as a property and then bind your repeater to list of this custom objects. This will allow you to use Eval method.

    Best wishes,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. HarryS
    HarryS avatar
    4 posts
    Registered:
    01 Nov 2006
    12 Oct 2010
    Link to this post
    Hi Ivan,

    Thanks for the response.

    Is there a sample anywhere you could point me to?
    Whilst I understand the code from the link you provided, I don't get how I can use that, as the links are embedded within the main 'Content' of the blog post, so that's where I am struggling as not sure how I pull those out. 

    Many Thanks,
    Harry


  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    12 Oct 2010
    Link to this post
    Hi HarryS,

    If you want to extract only the links you have to use regular expression. To resolve the entire content you can use LinkParser.ResolveLinks method.

    Kind regards,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Register for webinar
4 posts, 0 answered