views:

55

answers:

2

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 solution for me.

Any better solutions welcome as well. Thanks!

EDIT: The compile error I am getting is:

    Compiler Error Message: BC30201: Expression expected.
A: 

I'm more familiar to C# but what isn't working? Won't compile, or doesn't do what you expect? If it won't compile then perhaps there is a solution, but if it just isn't working maybe your data isn't what you expect?

Nate
@Nate, sorry should have posted that, I have edited my post to show the compile error. Thanks
jaywon
+1  A: 

Have you tried something like:

<ItemTemplate> 
           <div class='tab<%# IIf ( Container.ItemIndex = 0, "highlight", "")%> '>
               'Other stuff here 
            </div> 
</ItemTemplate>
Ed Schembor
I get "Name 'Container' is not declared." compile error for that?
jaywon
@Ed, hey you were right, the syntax was just a little off. Needed to be `<%# IIf ( Container.ItemIndex = 0, "highlight", "")%>`. Notice the missing pound sign in your example. If you update your post I'll check you off on the answer. Thanks!
jaywon
never mind got it for you, just got my edit privilege:) thanks again!
jaywon
Thanks for the edit.
Ed Schembor