Inline IF statement for ItemIndex asp:Repeater VB.NET
I am trying to do an inline IF statement inside a asp:Repeater control to add a class to the first item, but I can't quite seem to figure it out.
Basically the code I have right now that is not working 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 have tried using the OnItemDataBound
event but the delegate interface cannot return a value. If I'm going to do anything from a code-behind function really it would just need to be an "echo" kind of function which I wasn't quite sure how to get the item index in a code behind function. If I could do something inline like my example that would be the best solu开发者_高级运维tion for me.
Any better solutions welcome as well. Thanks!
EDIT: The compile error I am getting is:
Compiler Error Message: BC30201: Expression expected.
Have you tried something like:
<ItemTemplate>
<div class='tab<%# IIf ( Container.ItemIndex = 0, "highlight", "")%> '>
'Other stuff here
</div>
</ItemTemplate>
精彩评论