In a gridview, I have a column I use for images, using a template:
<asp:TemplateField HeaderText="Image">
<EditItemTemplate>
<%#GenerateControl(Eval("id").toString) %>
</EditItemTemplate>
<ItemTemplate>
<%#GetImageById(Eval("id"))%>
</ItemTemplate>
</asp:TemplateField>
I want generate a control, depending on wether the image exists or not. The code I use for doing this in the code behind is:
Protected Function GenerateControl(ByVal id As String) As String
Dim scrString As String = "../../Assets/Zalen/" + id + ".jpg"
Dim strImageUrl As String = Me.Server.MapPath(scrString)
If Not File.Exists(strImageUrl) Then
Return "<asp:FileUpload ID=""FileUpload1"" runat=""server"" />"
Else
Return "<asp:button ID=""Button1"" runat=""server"" Text=""Verwijder afbeelding"" OnClick=""DeleteImage(" + id + ")""/>"
End If
End Function
This is method is invoked by the GridView.Updating event.
So, basicly: If the image exists I want to show a button so that the user is able to delete the image. If the image does not yet exist (images are based on the primary key of the table ("id")) then I want to show a FileUpload control.
The controls show up in the HTML code when I run the website, but they do not show up on the website itself. (ie: visible through code, not visually)
How do I correctly render controls dynamicly into a GridView? Thanks