Inline IF statement for ItemIndex asp: Repeater VB.NET

I'm trying to make an inline IF statement inside an asp: Repeater control to add a class to the first element, but I can't figure out how to figure it out.

Basically, the code that I have now that does not work, but should give an idea of ​​what I'm trying to do, looks like this.

   <asp:Repeater ID="rptrTabRepeater" runat="server">
       <ItemTemplate>
           <div class="tab <%= If Container.ItemIndex = 0 Then %>highlight<% End If%>">
               'Other stuff here
            </div>
       </ItemTemplate>
   </asp:Repeater>

I tried to use the event OnItemDataBound, but the delegate interface cannot return a value. If I'm going to do something using a function with a code code, I just need to be an “echo” function that was not quite sure how to get the index of the element in the function behind the code. If I could do something inline, as in my example, this would be the best solution for me.

Any better solutions are welcome. Thank!

EDIT: Compilation error I get:

    Compiler Error Message: BC30201: Expression expected.
+3
source share
1 answer

Have you tried something like:

<ItemTemplate> 
           <div class='tab<%# IIf ( Container.ItemIndex = 0, "highlight", "")%> '>
               'Other stuff here 
            </div> 
</ItemTemplate>
+8
source

Source: https://habr.com/ru/post/1759593/


All Articles