我有一个Repeater控件嵌套在另一个Repeater控件中,如何使用下面的代码:
<input type="hidden" value='<%# Container.ItemIndex %>' />
指向第一个转发器吗?
我有一个Repeater控件嵌套在另一个Repeater控件中,如何使用下面的代码:
<input type="hidden" value='<%# Container.ItemIndex %>' />
这个问题很相似,虽然它谈论了如何从<HeaderTemplate>
访问属性,但是从<ItemTemplate>
也应该可以使用。
所以尝试使用<%# ((RepeaterItem)Container.Parent.Parent).ItemIndex %>
如果这不起作用,您可能需要更多的.Parent
s。暂时将一个ItemDataBound
处理程序附加到内部repeater,并使用RepeaterItemEventArgs
Item
属性返回与aspx中的Container
相同的对象的事实。因此,基本上评估e.Item.Parent
,e.Item.Parent.Parent
等,直到找到另一个RepeaterItem
为止。然后在aspx中使用相同数量的.Parent
s。
来自 MSDN:如何使用嵌套重复控件显示分层数据
这篇文章虽然有些年头了,但内容正是你所需要的。