ASP.Net Binding Repeater ArrayList as DataSource

Updated on 10 Aug 2012,
Published on 03 Sep 2008

In ASP.Net, you can display the items of ArrayList in a Repeater Data presentation control by binding the ArrayList variable using the DataSource property of Repeater. You can display the ArrayList collection of items in Repeater Control without using any for loop or while loop to get the items stored at each consecutive index. ArrayList collection allows you to store the items of different DataType e.g. string or integer that you can easily display in the form of ordered or unordered list view or table view by binding it to the ASP.Net Repeater Control.

Repeater Examples:

You can see the live samples and examples of Repeater Control from the following links:

HTML and CSS Design layouts enable you to display the ArrayList items in ASP.Net Repeater Control. E.g.: HTML UL and OL tags provide the unordered and ordered list layout whereas HTML table tag generates the table rows and columns.

C# Code for ASP.Net Binding Repeater ArrayList as DataSource

ArrayList arrlist = new ArrayList();

arrlist.Add("item 1");

arrlist.Add("item 2");

arrlist.Add(3);

arrlist.Add("item 4");

arrlist.Add("item 5");

Repeater1.DataSource = arrlist;

Repeater1.DataBind();

HTML OL LI Layout for ASP.Net Repeater Control

<asp:Repeater ID="Repeater1" runat="server">
    <HeaderTemplate>
        <ol>
    </HeaderTemplate>
    <ItemTemplate>
        <li><%#Container.DataItem %></li>
    </ItemTemplate>
    <FooterTemplate>
        </ol>
    </FooterTemplate>
</asp:Repeater>

Output:

Get the output for above discussed code from the following link:

Repeater ArrayList Binding

Continue to next tutorial: ASP.Net Repeater Data Binding with Youtube API RSS to learn how to display videos fetched using youtube feed.

2 Responses to "ASP.Net Binding Repeater ArrayList as DataSource"
Doh - <%#Container.DataItem %> forgot all about that (I was trying to use eval instead). Thanks for the tip, Adrian
Priyanshu Mishra
hi sir,
i have to populate a asp repeater using commerce server, my requirements are there should be three fields in the repeater viz, one button one label and one text box.
Can u guide me plz wid yours valuable suggestion
Leave a Comment
* required
* required
* will not be published
* optional
* hint: http://www.example.com
  • Subscribe via Email
  • HIRE EzineASP.Net Developers