472,982 Members | 2,116 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,982 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 9412
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: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
4
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

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.