Conditional logic inside repeater control?

In ASP.NET using VB, how can I do this on the page itself, and not in the code?

<ItemTemplate>
    <%  If Container.DataItem("filename") <> "" Then
        <a href="/pdf/"><%# Container.DataItem("filename") %>Agenda</a>
    End If%>
</ItemTemplate>
+5
source share
3 answers

Create a boolean property in the data source, for example. filenameExists and use this to bind to an invisible HyperLink property

<asp:HyperLink runat="server" Visible='<%# Eval("filenameExists ") %>' NavigateUrl="/pdf/">Agenda</asp:HyperLink>
+4
source

Using it ends, thanks for helping the guys!

On the page:

<asp:Literal ID="ltPDF" runat="server" Visible='<%# showPDF(Container.DataItem("filename")) %>'>Test</asp:Literal>

Code behind:

 Function showPDF(ByVal pdf As String) As Boolean
    If pdf <> "" Then
        Return True
    Else
        Return False
    End If
End Function
+1
source

There are no open and closing brackets for Ifand End If:

<ItemTemplate>
    <%  If Container.DataItem("filename") <> "" Then %>
        <a href="/pdf/"><%# Container.DataItem("filename") %>Agenda</a>
    <% End If %>
</ItemTemplate>
0
source

All Articles