views:

127

answers:

3

I need to display something such as below.

Type A

  1. Type A Item 1
  2. Type A Item 2
  3. Type A Item 3

Type B

  1. Type B Item 1
  2. Type B Item 2
  3. Type B Item 3

Type C

  1. Type C Item 1
  2. Type C Item 2
  3. Type C Item 3

All of the data comes from a dataset with columns 'Type' and 'ItemName'. Now an easy solution would be to create a repeater for each 'Type' and filter the data set by each 'Type'. However, I would like to just use one repeater and the problem with that is I need some way to recognize when each new section has a header.

<div>[Header][Item]</div>

[Header] = <b>Type A</b><br />
[Item] = Type A Item 1

So only the first item of each Type gets a header item and all others are set to an empty string.

Does anyone know any tricks that could help?

A: 

Ok, I just came up with a solution. Though it is pretty dirty.

I created a global variable to track the headers. The variable is a list of strings. OnItemDatabind I check if the header item is in the global list.

If the item doesn't exist, I add it to the list and display the header. Otherwise, the header item is empty.

So far this works, but I don't know how I feel about it.

Edit: I am wondering if another control may work better at this...

Ty
i have done something similar in the past, but i just have a string (current value) and only display header if it has changed, then update the current value
Darren Kopp
Take a look at the nested repeater concept below, it'll save you from a lot of this trouble.
EdgarVerona
+2  A: 

Instead of creating a repeater for each type, how about a nested repeater?

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

Try that out. You still will need more than one repeater, but in this case it'd only be two that you need, and you wouldn't have to make one for each type (as you were fearing) but rather one for types, and one nested within it for items. The link above should give you a good starting point to investigate further.

EdgarVerona
Nice, I like that solution much more than my hack. Thanks for the tip.
Ty
n/p, glad to help! =)
EdgarVerona
A: 

Assuming they're sorted by type, you don't need to keep an entire list: just the current item.

Look for more information on control/break reporting.

Joel Coehoorn