代码之家  ›  专栏  ›  技术社区  ›  jaywon

ItemIndex的内联IF语句asp:Repeater VB.NET

  •  3
  • jaywon  · 技术社区  · 14 年前

    我试图在 asp:Repeater 控件将类添加到第一项,但我似乎不太明白。

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

    我试过使用 OnItemDataBound 事件,但委托接口无法返回值。如果我要从一个代码隐藏函数做任何事情,它只需要是一个“echo”类型的函数,我不太确定如何在代码隐藏函数中获取项索引。如果我能像我的例子那样做一些内联的事情,那对我来说是最好的解决方案。

    编辑: 我得到的编译错误是:

        Compiler Error Message: BC30201: Expression expected.
    
    1 回复  |  直到 14 年前
        1
  •  8
  •   jaywon    14 年前

    你有没有试过这样的方法:

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