Victor
Victor

Reputation: 8480

Repeater inside a Repeater

I have a Repeater inside a Repeater, how can a use the code below:

<input type="hidden" value='<%# Container.ItemIndex %>' />

pointing to the first repeater?

Upvotes: 4

Views: 2828

Answers (2)

Rawling
Rawling

Reputation: 50104

This question is similar; although it talks about accessing a property from the <HeaderTemplate>, it feels like it should work from the <ItemTemplate>.

So try <%# ((RepeaterItem)Container.Parent.Parent).ItemIndex %>

If this doesn't work, you may need more .Parents. Try attaching an ItemDataBound handler to the inner repeater temporarily, and use the fact that the RepeaterItemEventArgs Item property returns the same object as Container gives in the aspx. So basically evaluate e.Item.Parent, e.Item.Parent.Parent etc. until you find the one that is another RepeaterItem. Then use the same number of .Parents in your aspx.

Upvotes: 7

NakedBrunch
NakedBrunch

Reputation: 49413

From MSDN: How To Display Hierarchical Data by Using Nested Repeater Controls

The article is a few years old but the content is what you're looking for.

Upvotes: 0

Related Questions