Click here to Skip to main content
15,306,376 members
Articles / Web Development / ASP.NET
Posted 19 Feb 2004


69 bookmarked

A quick guide to using nested repeaters in ASP.NET

Rate me:
Please Sign up or sign in to vote.
4.27/5 (41 votes)
19 Feb 2004CPOL2 min read
Using nested repeaters in ASP.NET with an XML data store


I've never really been much of a web-developer and never thought I'd find web-development all that interesting. But I must say I've been quite fascinated by what little ASP.NET I've done up till now, which is not a lot to be honest. One control I found particularly useful was the Repeater control, but I struggled a little when I tried to implement nested repeaters using an XML file as the data store. Eventually, the solution turned out to be embarrassingly easy, and I thought I'd write a little article for other first-timers who might encounter the same annoying situation I did.

Note to readers

I assume that you already know how to use a Repeater control. This article only shows you how to implement nested repeaters and will not attempt to explain repeaters in general.


I am going to demonstrate a simple ASP.NET web application that will list out a Cricket World XI using an XML file as the input-data. Eventually, modification of the team simply involves a change in the XML file with no changes required either in the aspx pages or in the code-behind files.

My XML file

Image 1

Essentially I have four categories - and each category has one or more players.

Implementing nested repeaters

I am going to list the categories first and inside each category I will list the players under that category. Lets first add the outter repeater that will list the categories.

Image 2

We now add the inner repeater to the <ItemTemplate> tag of the outter repeater.

Image 3

Writing the code-behind code

Alright, I know that "code-behind code" sounds weird, but I couldn't think of anything better sounding and if anyone has any better ideas, please drop me a line. Anyway we setup the first repeater in the Page_Load event handler as usual.

private void Page_Load(object sender, System.EventArgs e)
    DataSet ds = new DataSet();
    CategoryRepeater.DataSource = ds;

For setting up the outter repeater, we handle the ItemDataBound event of the Repeater class which is raised when an item is data-bound but before it is rendered on the page. We now get a reference to the PlayerRepeater control using RepeaterItem.FindControl and set its data source using CreateChildView and the automatic relation that's made for us - category_cricketer. By the way I was quite impressed by that, I never expected automatic relations to be created based on the XML. Pretty cool I think!

private void CategoryRepeater_ItemDataBound(object sender, 
    System.Web.UI.WebControls.RepeaterItemEventArgs e)
    RepeaterItem item = e.Item;
    if( (item.ItemType == ListItemType.Item) ||
        (item.ItemType == ListItemType.AlternatingItem) )
        PlayerRepeater = (Repeater) item.FindControl("PlayerRepeater");
        DataRowView drv = (DataRowView)item.DataItem;
        PlayerRepeater.DataSource = drv.CreateChildView("category_cricketer");

That's all.

The output

I got the below output when I viewed the web-form in my browser.

Image 4


Feedback and criticism is welcome as usual. I'd also like to thank Aravind Corera (Chennai based C# MVP) who gave me the right URLs to solve this problem when I was tearing my hair out in frustration.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Nish Nishant
United States United States
Nish Nishant is a Principal Software Architect based out of Columbus, Ohio. He has over 17 years of software industry experience in various roles including Lead Software Architect, Principal Software Engineer, and Product Manager. Nish was a Microsoft Visual C++ MVP between 2002 and 2015.

Nish is an industry acknowledged expert in the Microsoft technology stack. He authored C++/CLI in Action for Manning Publications in 2005, and had previously co-authored Extending MFC Applications with the .NET Framework for Addison Wesley in 2003. In addition, he has over 140 published technology articles on and another 250+ blog articles on his WordPress blog. Nish is vastly experienced in team management, mentoring teams, and directing all stages of software development.

Contact Nish : If you are interested in hiring Nish as a consultant, you can reach him via his google email id voidnish.

Company Website :

Comments and Discussions

QuestionNested Repeater with parametr Pin
Btihin1-Apr-15 0:17
MemberBtihin1-Apr-15 0:17 
AnswerRe: Nested Repeater with parametr Pin
Btihin8-Apr-15 0:37
MemberBtihin8-Apr-15 0:37 
QuestionGood Article Pin
Alireza_136219-Mar-13 22:45
MemberAlireza_136219-Mar-13 22:45 
QuestionPossible to include paging? Pin
Tyng20-Jan-13 14:24
MemberTyng20-Jan-13 14:24 
QuestionA better Tutorial here Pin
tim cadieux26-Jul-12 6:50
Membertim cadieux26-Jul-12 6:50 
GeneralBetter Way!! PinPopular
imsathy20-Jan-08 23:40
Memberimsathy20-Jan-08 23:40 
GeneralRe: Better Way!! Pin
Maciej Pilichowski5-Mar-11 23:31
MemberMaciej Pilichowski5-Mar-11 23:31 
GeneralRe: Better Way!! Pin
Marco Bertschi4-Mar-13 7:36
professionalMarco Bertschi4-Mar-13 7:36 
QuestionI have a problem when use printed review to check nested repeater aspx pages Pin
YingHsuan25-Nov-07 23:02
MemberYingHsuan25-Nov-07 23:02 
AnswerRe: I have a problem when use printed review to check nested repeater aspx pages Pin
YingHsuan27-Nov-07 4:47
MemberYingHsuan27-Nov-07 4:47 
GeneralWith tableAdapter instead of xml file Pin
werge14-Sep-07 10:14
Memberwerge14-Sep-07 10:14 
GeneralNested Repeaters Pin
remya3003@yahoo.com22-Jun-06 17:36
Memberremya3003@yahoo.com22-Jun-06 17:36 
GeneralProblem in Converting Pin
KevinBhavsar3-Apr-06 1:18
MemberKevinBhavsar3-Apr-06 1:18 
Generali want to bind to a table not xml file with teh same issue title and users under tile Pin
GiiiO8-Nov-05 23:28
MemberGiiiO8-Nov-05 23:28 
Generali want to bind to a table not xml file with teh same issue title and users under tile Pin
GiiiO8-Nov-05 23:28
MemberGiiiO8-Nov-05 23:28 
GeneralRequires at least two Child Nodes Pin
javafreddie6-Apr-05 15:55
Memberjavafreddie6-Apr-05 15:55 
GeneralRe: Requires at least two Child Nodes Pin
SeveQ3-Jul-07 9:06
MemberSeveQ3-Jul-07 9:06 
GeneralThis code cant be complete Pin
Anonymous31-Mar-05 3:33
MemberAnonymous31-Mar-05 3:33 
GeneralRe: This code cant be complete Pin
EntilzhaFini30-Sep-06 9:45
MemberEntilzhaFini30-Sep-06 9:45 
GeneralRe: This code cant be complete Pin
Alex Stephens7-Jan-13 2:32
MemberAlex Stephens7-Jan-13 2:32 
GeneralNested User Controls Pin
Miszou14-Feb-05 14:05
MemberMiszou14-Feb-05 14:05 
Generalneed more explanation. Pin
purplerain22-Sep-04 10:20
Memberpurplerain22-Sep-04 10:20 
GeneralAn alternative Pin
Ian Darling21-Feb-04 1:30
MemberIan Darling21-Feb-04 1:30 
GeneralRe: An alternative Pin
SGalloway21-Feb-04 1:39
MemberSGalloway21-Feb-04 1:39 
GeneralRe: An alternative Pin
Ian Darling21-Feb-04 1:42
MemberIan Darling21-Feb-04 1:42 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.