Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Here's how I would do it:</p> <pre><code>&lt;asp:TemplateField HeaderText="Image"&gt; &lt;EditItemTemplate&gt; &lt;asp:FileUpload ID="FileUpload1" runat="server" Visible='&lt;%#GenerateControl(Eval("id").ToString()) %&gt;' /&gt; &lt;asp:button ID="Button1" runat="server" Text="Verwijder afbeelding" CommandArgument='&lt;%#Eval("id").ToString() %&gt;' CommandName="DeleteImage" Visible='&lt;%#GenerateControl(Eval("id").ToString()) %&gt;' OnClick="DeleteImage" /&gt; &lt;/EditItemTemplate&gt; &lt;ItemTemplate&gt; &lt;%#GetImageById(Eval("id"))%&gt; &lt;/ItemTemplate&gt; &lt;/asp:TemplateField&gt; </code></pre> <p>Then in the code behind:</p> <pre><code>Protected Function GenerateControl(ByVal id As String) As Boolean Dim scrString As String = "../../Assets/Zalen/" + id + ".jpg" Dim strImageUrl As String = Me.Server.MapPath(scrString) Return File.Exists(strImageUrl) End Function </code></pre> <p><strong>Note:</strong> I have assumed that you are using a code behind method to perform the delete, so I chose to include CommandArgument and CommandName. This makes the OnClick assignment unnecessary since you would handle these 2 properties in the OnRowCommand event. Though the property of CommandArgument could still be used in the OnClick and would be meaningful.</p> <p>I've found it easier when trying to decide which control to use just to use them both and turn one "off" if I don't need i. This is not terribly efficient since it still goes through the computational process up until render, but this is usually negligible and it never makes it out to the html.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload