Home > DeveloperSection > Forums > If statement inside Repeater control
Goti Bandu

Total Post:119

Points:835
Posted on    June-02-2015 7:39 AM

 ASP.Net C# 
Ratings:


 1 Reply(s)
 669  View(s)
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.



Kamlakar Singh
Kamlakar Singh

Total Post:194

Points:1396
Posted on    June-02-2015 8:04 AM

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 --%>

       <%End If%>

    </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" %>


Don't want to miss updates? Please click the below button!

Follow MindStick