关闭图像并以字符串格式嵌入代码 (ASP)

Close Image and Embed code in String Format (ASP)

我的代码在"Item Template - asp:repeater element"

当我尝试将它们打印到我的页面 (aspx) 时,如果图像已经显示,有时嵌入的视频播放器无法显示。我认为这是未关闭标签(图像和嵌入标签)的原因。如何关闭 StringFormat 中的 this 元素。我是编程新手,抱歉我的英语不好。

这是我的代码:

<%#(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())) %>

我想你失踪了 > :

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

这里:

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

编辑

也许你可以这样重写你的代码以获得更好的效果 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>

此致