Click here to Skip to main content
15,921,774 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
Hi Guys,

I have a table which looks like this

1 | Transport |  Bus-Service | .....

2 | Transport | Tain-Service | ......

3 | Facilities  | Bus-Service..| ...

4 | Facilities  | Rail-service..| .....


and my objective is to display

Transport

   Bus Service ....

   Train Service...

Facilities

   Bus Service..

   Tain Service...


This Data is coming from database.. Now what I am doing is on server side I am looping through the table like if(data == "Transport") and binding all it's corresponding data into one repeater... and same with Facilities..

Now my UI looks like

XML
   <h2> Transport </h2>

 <asp> repeater databind= "Transport looped data"...

<h2> facilities </h2>

<asp> repeater databind ="Facilities looped data"...

But ideally this is not looking good(hard coding header)

I am trying to do like this so that I don't have to hard code for each header..

<asp> ListView ...>

<itemtemplate>

   <h2> header(From database) </h2>

   <repeater>

       data.....

</repeater>

</itemTemplate>


My problem is for one header there are sub items.. I have to display header only once

How do I get rid of header duplicates???

Any idea .. Thanks alot
Posted
Updated 28-Jan-23 1:17am
v2

If I understood your problem correctly, I would replace the ListView with a TreeView[^]

Here is a nice article on binding data to the TreeView:
Binding Data With ‘TreeView’ Control Asp.net 2.0[^]

Best regards
Espen Harlinn
 
Share this answer
 
Hi,
Nested repeater control should solve your problem. The idea is Column2 (Transport/Facilities) will bind to outer repeater and inner repeater will bind Column3(Bus-Service/Tain-Service) specific to respective outer repeater value, this way you do not have to hard code any value. Similar idea implementation references is given below,

A quick guide to using nested repeaters in ASP.NET[^]
http://idunno.org/archive/2004/10/30/145.aspx[^]
http://www.jamesewelch.com/2008/03/06/how-to-use-nested-repeater-controls-with-relational-data/[^]
Hope this will help.
 
Share this answer
 
Comments
Jayadheer Reddy 17-Jul-11 20:02pm    
Thanks for your response. I did the same. I created a class which holds one header value and list of all elements that belongs to that header. I made a list and bind it to ListView in which I have used nested repeater controls..
Thanks a lot..

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900