简体   繁体   中英

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?

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 .Parent s. 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 .Parent s in your aspx.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM