Inject Index of Current item when binding to a rep

2019-05-03 23:42发布

问题:

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