Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to count the number of items in an asp repeater?

How to count the number of items in a repeater using ASP.NET?

I would like to display something along the lines of:

MARKUP

Page 1 of 5

ASPX

Get Item Index: (working)

<%# DataBinder.Eval(Container, "ItemIndex", "") + 1%>

Count total items: (failing)

<%# DataBinder.Eval(Container.ItemIndex, rpt.Items.Count)%>

I would prefer to do this on page however am open to suggestions and code behind.

like image 780
DreamTeK Avatar asked Nov 22 '25 08:11

DreamTeK


1 Answers

This is the best solution I get it

<asp:Repeater ID="rptGallery" runat="server"  >
    <ItemTemplate>
        <div>
            <div>        
                <asp:Label ID="Number_of_element_in_repeater" runat="server"
                Text='<%#Convert.ToString(((IList((Repeater)Container.Parent).DataSource).Count) %>'>
                </asp:Label>

            </div>
        </div>
    </ItemTemplate>
</asp:Repeater>

The number of items in repeater is:

Convert.ToString(((IList)((Repeater)Container.Parent).DataSource).Count)
like image 76
Ahmad Joumah Avatar answered Nov 24 '25 21:11

Ahmad Joumah