If statement inside Repeater control

Total Post:119

Points:835
C# 
 1548  View(s)
Ratings:
Rate this:

Although there are several questions on this topic, I haven't found any satisfactory answers.

I have a Repeater that needs to display complex content. An IF statement is required within the template. I can't move this to the code-behind as I need to have server controls and user controls registered within the repeater. Here is what I need:

<asp:Repeater ID="rCom" runat="server" ClientIDMode="Static">
    <ItemTemplate>
       <%# If CBool(Eval("IsFix")) Then%>
           <%-- HTML content including server and user controls --%>
       <%Else%>
           <%-- HTML content including server and user controls --%>
       <%End If%>
    </ItemTemplate>
</asp:Repeater>

The above throws a compiler error. Any idea on how to achieve this? I need to evaluate the IsFix field in the If statement.

  1. Post:194

    Points:1396
    Re: If statement inside Repeater control

    Remove # from the code nuggets which is having if statement:- 

    <asp:Repeater ID="rCom"runat="server" ClientIDMode="Static">
        <ItemTemplate>
           <%CBool(Eval("IsFix")) Then%>
               <%--HTML content including server and user controls --%>
           <%Else%>
               <%--HTML content including server and user controls --%>
           <%EndIf%>
        </ItemTemplate>
    </asp:Repeater>

    Edit:

    Try with conditional operator (I am not sure about the syntax in VB.NET, please check):-

    <%# If(CBool(Eval("IsFix")), "Do Something", "Else do something" %>

      Modified On Apr-09-2018 11:49:52 PM

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!