0

My codes are in "Item Template - asp:repeater element"

When i try print them to in my page (aspx) sometimes embed video player can not be displayed if image displayed already. I think it is happening cause of not closed tags (image and embed tags). How can i close the this elements in StringFormat. I'm newbie at programming and sorry for my bad English.

Here my codes:

<%#(String.IsNullOrEmpty(Eval("image").ToString()) ? "" : String.Format("<img class='img-thumbnail' style='margin-top:15px !important; margin-bottom:15px !important; width:300px; margin: 0 auto;' src='http://example.com/image/{0}'" , Eval("image").ToString()))%>


<%#(String.IsNullOrEmpty(Eval("embed").ToString()) ? "" : String.Format("<iframe style='margin-left: 20px;' width='300' height='169' src='https://www.youtube.com/embed/{0}'" , Eval("embed").ToString())) %>

1 Answers1

0

I think you re missing > :

src='http://example.com/image/{0}' >"

and here :

src='https://www.youtube.com/embed/{0}'>"

Edit

May be you could rewrite your code that way for better maintenance/readability :

<ul>
    <asp:Repeater runat="server" ID="repeater1">
        <ItemTemplate>
            <li>
                <asp:Image runat="server"
                    Visible='<%# Eval("image") != null %>'
                    ImageUrl=<%# "http://example.com/image/" + Eval("image") %> />
            </li>
        </ItemTemplate>
    </asp:Repeater>
</ul>

Regards

Emmanuel DURIN
  • 4,803
  • 2
  • 28
  • 53
  • Thank you, it worked. and i did it for embed code like: src='https://www.youtube.com/embed/{0}'> " – Paramecium Nov 02 '15 at 10:35
  • You could have a look at that post to see some more ideas (to more easily use code) : http://stackoverflow.com/a/1171292/5295797. I didn't try. But it seems interesting – Emmanuel DURIN Nov 02 '15 at 10:38