0
votes

I'm creating a control that will mimic the functionality of a 'grouped repeater', whilst allowing them to define a template for each group header and another template for each group item.

My approach to this is to create a new class that has two public ITemplate members that will expose a way of defining the markup for these two templates on the page. I will then take the first template and assign it to the ItemTemplate of the 'parent repeater' and then the second template will be assigned to the ItemTemplate of the child repeater.

All fine so far.

Now I'm left with the problem of adding the child repeater to the ItemTemplate of the parent. A solution to this would be to add a control (possibly a placeholder) to the ItemTemplate of the parent repeater and then, on ItemDataBound, add the child repeater to the control collection of the placeholder, but I don't have this luxury as I cannot assume a PlaceHolder will be declared in the ItemTemplate on the page's markup.

I either need to:

A. Add the child repeater to the ItemTemplate of the parent repeater programmatically some other way (I don't know how)

or

B: Add a placeholder to the ItemTemplate of the parent repeater so that on ItemDataBound I can do what I need to do to get the child repeater in there

A suggestion of how I could achieve either of the two above solutions is what I'm after. Any help much appreciated.

I'm also open to alternative approaches if necessary.

1

1 Answers

0
votes

I've solved this one, and I didn't find much in the way of articles to help me so I'll post the answer just in case somebody else comes across it.

I have extended ITemplate to create 'NestedRepeaterItemTemplate'. This new class takes a repeater as a parameter to the constructor and then adds this repeater (the child repeater) to a new placeholder I create in the InstantiateIn method override.

The part of the code that actually uses this class to add the child to the parent repeater could look like:

parentRepeater.ItemTemplate = new NestedRepeaterItemTemplate(childRepeater);

And prior to this code, I've already added the GroupItemTemplate to the ItemTemplate of the child repeater.

Sorted.