How to wrap image in <a></a> based on condition in asp.net repeater?
<p>Lets say I have a data table with the columns ImageUrl, Text, LinkUrl and Title.</p>

<p>I databind this to a repeater and displays everything without any issue. However, LinkUrl can be empty and then I want the code to be like the one below. If the LinkUrl contains a string/link then I want to wrap the image with a link to the URL. Please ask questions if I need to clarify more.</p>

<p>Example code:</p>

<pre><code>&lt;asp:Repeater runat="server" ID="rptImageGallery"&gt;
&lt;ItemTemplate&gt;
&lt;div class="slide"&gt;
    &lt;asp:Image ID="Image1" runat="server" ImageUrl='&lt;%#UrlHelper(DataBinder.Eval(Container.DataItem, "ImageUrl"))%&gt;'&gt;
    &lt;h2&gt;&lt;%# DataBinder.Eval(Container.DataItem, "Title") %&gt;&lt;/h2&gt;
    &lt;p&gt;&lt;%# DataBinder.Eval(Container.DataItem, "Text")%&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;/ItemTemplate&gt;
&lt;/asp:Repeater&gt;
</code></pre>

<p>Code behind:</p>

<pre><code>DataTable dt = new DataTable();
dt = collListItems.GetDataTable().AsEnumerable()
    .Where(a =&gt; Convert.ToString(a["Published"]) == "1")
        .CopyToDataTable();

rptImageGallery.DataSource = dt;
rptImageGallery.DataBind();
</code></pre>

<p>So if the current row contains a link in LikUrl then I want the repeater to present something like this</p>

<pre><code>&lt;asp:Repeater runat="server" ID="rptImageGallery"&gt;
&lt;ItemTemplate&gt;
&lt;div class="slide"&gt;
    &lt;asp:Image ID="Image1" runat="server" ImageUrl='&lt;%# UrlHelper(DataBinder.Eval(Container.DataItem, "FileLeafRef"))%&gt;' /&gt;
    &lt;a href='&lt;%# DataBinder.Eval(Container.DataItem, "LinkUrl")%&gt;' runat="server"&gt;&lt;%# DataBinder.Eval(Container.DataItem, "Title") %&gt;&lt;/h2&gt;&lt;/a&gt;
    &lt;p&gt;&lt;%# DataBinder.Eval(Container.DataItem, "Text")%&gt;&lt;/p&gt;                       
&lt;/div&gt;
&lt;/ItemTemplate&gt;
&lt;/asp:Repeater&gt;
</code></pre>

<p>Any suggestions on how to achieve this?</p>

<p>Edit: something weird with the post. When I go Edit I can see the correct code - slick Save and it doesn't update my code example. Anyway, in the last code part I want a link wrapping the image or image text.</p>
