Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Conditional logic inside Repeater Control?

Tags:

asp.net

vb.net

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

<ItemTemplate>
    <%  If Container.DataItem("filename") <> "" Then
        <a href="/pdf/"><%# Container.DataItem("filename") %>Agenda</a>
    End If%>
</ItemTemplate>
like image 941
lgriffin Avatar asked Jun 11 '12 17:06

lgriffin


2 Answers

Create a boolean property in your data source e.g. filenameExists and use this to databind against the Visible property of a HyperLink

<asp:HyperLink runat="server" Visible='<%# Eval("filenameExists ") %>' NavigateUrl="/pdf/">Agenda</asp:HyperLink>
like image 96
graham mendick Avatar answered Sep 28 '22 01:09

graham mendick


Ended up using this, thanks for your help 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
like image 38
lgriffin Avatar answered Sep 28 '22 00:09

lgriffin