WorldofASP.NET : ASP.NET Directory, Tutorial, Hosting, and Source Code
You are 1 of 105 users


WorldofASP.NET >> ASP.NET >> Unedited ASP.NET

Repeater within Repeater

this article is used to show hierarchical data using repeater control.
Published Date : 11 Jul 2008
Author : zafar iqbal
Language : C#
Platform : .NET
Technology : ASP.NET
Views : 1685
Rating : (0 votes so far)



Download NestedRepeater.zip

Introduction

This article is usefull to show hierarchical data using repeater control.

Description

Basically this project shows how to embed one repeater into another repeater.A parent repeater is used to display the main headings and child repeater populates the data according to headings. An xml file is used as datasource to display data.

XML File

<?xml version="1.0" encoding="utf-8" ?>
<Groups>
<category GroupId="1">
  <Name>Test 1</Name>
  <Name>Test 2</Name>
  </category>
 <category GroupId="2">
 <Name>Test 3</Name>
  </category>
<category GroupId="3">
  <Name>Test 4</Name>
  <Name>Test 5</Name>
  </category>
</Groups>

The above code is used to create a xml file called Group.xml. and is used as a datasource.GroupId Field is used to show the main headings And name field is used to show the child items based on the GroupId.

Aspx File

<asp:Repeater id="ParentRepeater" runat="server" OnItemDataBound="ParentRepeater_ItemDataBound"><
HeaderTemplate>
<h2>Group Information</h2><ul>
</HeaderTemplate>
<FooterTemplate>
</ul>
</FooterTemplate>
<ItemTemplate>
<li><b><%# Eval("GroupID") %></b></li>
<%-- adding one more repeater within this item template --%>
<asp:Repeater id="ChildRepeater" runat="server"> <HeaderTemplate>
<ul>
</HeaderTemplate> <FooterTemplate>
</ul>
</FooterTemplate>
<ItemTemplate>
<li><%# Eval("Name_Text") %></li> </ItemTemplate>
</asp:Repeater>
</ItemTemplate>
</asp:Repeater>

Codebehind File

protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
DataSet ds = new DataSet();
ds.ReadXml(HttpContext.Current.Server.MapPath("./Group.xml"));
ParentRepeater.DataSource = ds;
ParentRepeater.DataBind();
 }
}
protected void ParentRepeater_ItemDataBound(object sender,RepeaterItemEventArgs e)
{
RepeaterItem item = e.Item;
if (item.ItemType == ListItemType.Item || item.ItemType == ListItemType.AlternatingItem)
{
Repeater ChildRepeater = (Repeater)item.FindControl("ChildRepeater");
DataRowView drv = (DataRowView)item.DataItem;
ChildRepeater.DataSource = drv.CreateChildView("category_Name");
// here u can also bind the Child Repeater with DataTable like 
//ChildRepeater.DataSource = datatableName;
ChildRepeater.DataBind();
}
}

In the above code a dataset is used to read the xml file from path. MapPath() is used to find the path of xml file and repeater binds from dataset.Now onItemDataBound event of the ParentRepeater we find the main heading and binds childrepeater based on the GroupId.
Download this project to view more information.

Conclusion

This is nice to show hirarchical data using repeaters. 

  1. Search Engine
  2. ASP.NET Resources

Download Source Code


                



Other Related and Popular Articles :

Simple asp2 feedback form
A simple way to get user feedback via webpage email.

Designing a Membership Sign-Up and Login Page in ASP.NET
How to design user interface for registration and login in ASP.NET

Validate Email and Domain in a Web Form
Simple method to validate using javascript and ASP.NET validation control

Basics of XHTML-MP
Basics of XHTML-MP

Activate User Registration by Email in ASP.NET
How to activate registered user using System.Net.Mail.SMTPClient class

Implement captcha control library for ASP.NET
a captcha control, image, image handler, and supression class for form validation


Author Profile : zafar iqbal

Hi,
I am zafar iqbal working as a Software Engineer
in Lucknow with SRM TechSol pvt. ltd.

Thanks,
zafar iqbal

Click here to view Author Profile


How would you rate the quality of this content?
Poor Excellent

Comments

Leave New Comments


Article Content copyright by zafar iqbal
Everything else Copyright © by WorldofASP.NET 2009

Category
.NET 3.5
AJAX and ATLAS
ASP.NET
C# Programming
Classic ASP
Enterprise Systems
General .NET
VB.NET Programming
Announcements
Earn Cash by writing an article or review
For more info Click here







Legend : - Within 3 Days - Within 6 Days - Within 9 Days

Home | Add Resources | Sponsored Listings | Advertise with Us | SiteMap 1 | SiteMap 2 | Link To Us | Contact Us
© 2002-2009 Worldofasp.net ASP.NET Directory, Hosting and Tutorials | All rights reserved
Our Partners : ASP.NET Web Hosting | Windows Web Hosting | ASP.NET Hosting | Phone Card | PHP Directory | Bangkok Hotels |Calling Card |Stock Investing