[英]How to get the parent item index inside child repeater?
I have nested repeaters like this: 我有这样的嵌套中继器 :
<asp:Repeater ID="rptQuestoes" runat="server">
<HeaderTemplate>
<ol class="orderedList">
</HeaderTemplate>
<ItemTemplate>
<li>
<%#DataBinder.Eval(Container.DataItem, "QuestionName")%>
<asp:Repeater ID="rptAlternativas" DataSource='<%# Container.DataItem.Row.GetChildRows("Questionario") %>' runat="server">
<HeaderTemplate>
<ul style="list-style-type: none">
</HeaderTemplate>
<ItemTemplate>
<li>
<input id="rb" type="radio" name='ITEM_INDEX_HERE' value='<%#Container.DataItem("AlternativeID")%>' /><%#Container.DataItem("AlternativeName")%>
</li>
</ItemTemplate>
<FooterTemplate>
</ul>
</FooterTemplate>
</asp:Repeater>
</li>
</ItemTemplate>
<FooterTemplate>
</ol>
</FooterTemplate>
</asp:Repeater>
I want to print the parent item index inside the child repeater (rptAlternativas) in VB right in ITEM_INDEX_HERE
marker. 我想在ITEM_INDEX_HERE
标记中的VB的子转发器(rptAlternativas)中打印父项索引 。 How can I achieve this? 我该如何实现?
I hope someone can give you a better answer than this, but I would consider adding a property to your "Quentionario" sub elements. 希望有人能给您比这更好的答案,但是我会考虑向您的“ Quentionario”子元素中添加一个属性。
<asp:Repeater ID="rptAlternativas"
DataSource='<%# Container.DataItem.Row.GetChildRows("Questionario") %>'
runat="server">
Can you add a question id to each of these objects? 您可以为每个对象添加一个问题ID吗? You're already binding to their AlternativeId
in your radio button, adding a question id to these objects would let you do simply: 您已经在单选按钮中绑定了它们的AlternativeId
,向这些对象添加一个问题ID可以使您简单地执行以下操作:
<input id="rb" type="radio" name='<%#Container.DataItem("QuestionId")%>' value='<%#Container.DataItem("AlternativeID")%>' />
Even if these objects are auto-generated from an ORM, you should be able to add the property in via a partial class, and then just set the appropriate values in a simple loop. 即使这些对象是从ORM自动生成的,您也应该能够通过局部类添加该属性,然后只需在一个简单的循环中设置适当的值即可。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.