473,396 Members | 1,812 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Nested repeaters with a single datatable

If I have a datatable which looks like this:

Record Id, Group Id, Name
1, 1, Test 1
2, 1, Test 2
3, 2, Test 3
4, 3, Test 4

Is it possible to use nested repeaters to group the information by GroupId?
e.g. displaying something like

Group 1
Test 1
Test 2
Group 2
Test 3
Group 3
Test 4

I normally do this with two datatables inside a dataset and link the group
id column, but in this case I only have a flat datatable like the above.

TIA

--
Leon Mayne
http://leon.mvps.org/

Jun 27 '08 #1
3 9438
Hi

In Item data bound of repeater populate the nested repeater...

http://www.codeproject.com/KB/aspnet...Repeaters.aspx

Best of luck

Munna
www.munna.shatkotha.com
www.munna.shatkotha.com/blog
www.shatkotha.com
Jun 27 '08 #2
You can, if you wish, try nested repeaters, but you can easily get away with
just one repeater.

Make an itemtemplate as 2 table rows. Put group id in the top row and record
name and id in the second. Make your data source return records sorted by
group id. Databind the repeater. In the PreRender event loop through the
repeater items and hide all group rows except the first for every group id.
That's it.

A big advantage of this way over nested repeaters is that all record rows
will be aligned nicely since they are all in the same table.

--
Eliyahu Goldin,
Software Developer
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net
"Leon Mayne" <le**@rmvme.mvps.orgwrote in message
news:BC**********************************@microsof t.com...
If I have a datatable which looks like this:

Record Id, Group Id, Name
1, 1, Test 1
2, 1, Test 2
3, 2, Test 3
4, 3, Test 4

Is it possible to use nested repeaters to group the information by
GroupId? e.g. displaying something like

Group 1
Test 1
Test 2
Group 2
Test 3
Group 3
Test 4

I normally do this with two datatables inside a dataset and link the group
id column, but in this case I only have a flat datatable like the above.

TIA

--
Leon Mayne
http://leon.mvps.org/

Jun 27 '08 #3
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>
</category>
</Groups>
================================================== ==
Now I am going to take repeater control on the form-- -----

<asp:Repeater id="CategoryRepeater" runat="server" OnItemDataBound="CategoryRepeater_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="PlayerRepeater" runat="server">
<HeaderTemplate>
<ul>
</HeaderTemplate>
<FooterTemplate>
</ul>
</FooterTemplate>
<ItemTemplate>
<li><%# Eval("Name_Text") %></li>
</ItemTemplate>
</asp:Repeater>
</ItemTemplate>
</asp:Repeater>
=================================================
next proceed to Code Behind File ----------

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
DataSet ds = new DataSet();
ds.ReadXml(MapPath("./Group.xml"));
CategoryRepeater.DataSource = ds;
CategoryRepeater.DataBind();
}
}
protected void CategoryRepeater_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
RepeaterItem item = e.Item;
if (item.ItemType == ListItemType.Item || item.ItemType == ListItemType.AlternatingItem)
{
Repeater PlayerRepeater = (Repeater)item.FindControl("PlayerRepeater");

DataRowView drv = (DataRowView)item.DataItem;
PlayerRepeater.DataSource = drv.CreateChildView("category_Name");

// here u can also bind the Child Repeater with DataTable like
//PlayerRepeater.DataSource = datatableName;
PlayerRepeater.DataBind();
}
}
}
Jul 2 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: DonRex | last post by:
Hello all! I couldn't find a web application-newsgroup for ASP.NET, so I'm sorry if this is the wrong forum! Synopsis: In my webform I have 3 nested repeaters: rpWeeks ----- rpTime
2
by: Ed Allan | last post by:
I have extended the example at http://support.microsoft.com/default.aspx?scid=kb;EN- US;306154 to build a webform page with 3 layers of nested Repeaters (ie. parent, child and grandchild). I...
0
by: Ed Allan | last post by:
http://ejaconsulting.com/nestedrepeater/NestedRepeater.txt >-----Original Message----- >Doh! The HTML has all been rendered . . . > >Right click on this link and select 'Save target as ..' >to...
0
by: Paul | last post by:
I want to be able to nest a repeater in a datagrid or datalist. I'm not unduly bothered about a master/child relationship as such as there'll at this stage only ever be one record on the page, but...
0
by: Machi | last post by:
let say in parent-child scenerio (Product: Product Category - one product category may has many products), i am using nested repeaters where parent repeater will be used to display info and child...
4
by: =?Utf-8?B?SmFtZXMgR2V1cnRz?= | last post by:
On my page, I have one repeater that contains a literal control and a nested repeater. The nested repeater contains a literal control. Both repeaters are databound with only one object (string). ...
2
by: Josh | last post by:
I have a nested repeater situation with a Link Button on the nested repeater. However when the link button is clicked I get a postback but the event never takes place. I'm trying to wire up the...
1
PrinsonG
by: PrinsonG | last post by:
My Query is How do I export to excel/csv using Nested Repeaters. My project is web-based and i am using C#.Net. In this i use three repeaters. one displays ID, Name of the user. second...
1
by: andrew.douglas11 | last post by:
Hello all, Is it possible to share controls inside a child repeater? Here's the situation: I have a web page that needs to display data grouped by A, and alternatively by B (only one grouping...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.