Inject Index of Current item when binding to a repeater

半世苍凉 提交于 2019-12-10 09:34:49

问题


I am binding a List<HtmlImage> to a repeater

Its actually a nested repeater and the list is one of the properties that the parent repeater is binding to

I want to spit out the index of the current dataitem into the id property of the <li>

I've put a comment where I want the index to appear below

I have the following:

 <asp:Repeater ID="ImageListRepeater" runat="server" DataSource='<%# DataBinder.Eval(Container.DataItem, "Images") %>'>
                            <HeaderTemplate><ul></HeaderTemplate> 
                            <ItemTemplate>
                                <li id='<% **I want the Index Here**  %>'><%# RenderImage(Container.DataItem)%></li>
                            </ItemTemplate>
                            <FooterTemplate></ul></FooterTemplate>
    </asp:Repeater> 

What are the options?

thanks


回答1:


Have you tried <%# Container.ItemIndex %> ?



来源:https://stackoverflow.com/questions/1722486/inject-index-of-current-item-when-binding-to-a-repeater

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!