简体   繁体   English

中继器内的中继器

[英]Repeater inside a Repeater

I have a Repeater inside a Repeater, how can a use the code below: 我在Repeater中有一个Repeater,如何使用下面的代码:

<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> . 虽然它谈到从<HeaderTemplate>访问属性,但感觉它应该从<ItemTemplate>

So try <%# ((RepeaterItem)Container.Parent.Parent).ItemIndex %> 所以尝试<%# ((RepeaterItem)Container.Parent.Parent).ItemIndex %>

If this doesn't work, you may need more .Parent s. 如果这不起作用,您可能需要更多.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. 尝试暂时将ItemDataBound处理程序附加到内部转发器,并使用RepeaterItemEventArgs Item属性返回与aspx中Container给出的对象相同的事实。 So basically evaluate e.Item.Parent , e.Item.Parent.Parent etc. until you find the one that is another RepeaterItem . 所以基本上评估e.Item.Parente.Item.Parent.Parent等,直到找到另一个RepeaterItem Then use the same number of .Parent s in your aspx. 然后在aspx中使用相同数量的.Parent

From MSDN: How To Display Hierarchical Data by Using Nested Repeater Controls 从MSDN: 如何使用嵌套的转发器控件显示分层数据

The article is a few years old but the content is what you're looking for. 这篇文章已有几年历史了,但内容正是您所需要的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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