Access parent DataItem in nested repeater

Every once in a while a presentation comes along that requires multiple nested repeaters. The majority of times I’ve encountered this, there is something special that needs to be done to the last item in the inner repeater. With one repeater, this sort of thing is trivial. For example, I may use this logic to set the html element’s class:

Once you start nesting repeaters, this approach breaks since you can’t access the inner repeater control’s ID in this way. I don’t want to use the DataBound event in this case because I like keeping the class names inline in the code-front so designers can find them quickly. Instead, I access the parent’s DataItem like this:

In this case, (RepeaterItem)Container.Parent.Parent does the trick.

This entry was posted in it and tagged , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>