4

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?

Victor
  • 7,620
  • 14
  • 74
  • 121
  • 4
    please specify what you want to achieve. maybe there is other way around. – Kamran Pervaiz May 23 '12 at 12:58
  • Agree with Kamran. You will be producing N*M markup, when just N will likely suffice. – Mike Guthrie May 23 '12 at 13:20
  • Guys, it's simple! In two Repeaters, one inside the other, I want to access the Container properties for the first! I don't want to resolve my problem, I want to understand the asp.net structure! ;) – Victor May 23 '12 at 13:45

2 Answers2

7

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.

Community
  • 1
  • 1
Rawling
  • 45,907
  • 6
  • 80
  • 115
0

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.

NakedBrunch
  • 45,899
  • 13
  • 69
  • 97
  • I have already read this article and it doesn't anwser my question. It's only shows how to populate a Repeater inside another Repeater, and not how access differents Containers. – Victor May 23 '12 at 12:54
  • @Victor: did you downvote this? see, your question is very vague and the answer shows you how build nested repeater. please be more elaborate while asking question to get correct answers. please keep in mind that [Stackoverflow is not a mind reader](http://meta.stackexchange.com/a/128551/143130) – naveen May 23 '12 at 13:23
  • @naveen The question is no vague. I say that I want to use the code pointing to the first Repeater. It's clear, maybe you don't read well. Then, I don't downvote the answer! – Victor May 23 '12 at 13:39