Dou*_*low 7 c# asp.net webforms
可以说我有一个看起来像这样的类结构:
public class A
{
public string Poperty1 { get; set; }
public string Poperty2 { get; set; }
public List<B> Property3 { get; set; }
}
public class B
{
public string Property4 { get; set; }
public string Property5 { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
......以及几个看起来像这样的嵌套转发器:
<asp:Repeater ItemType="A" runat="server">
<ItemTemplate>
<asp:Label Text="<%# Item.Property1 %>" runat="server" />
<asp:Repeater runat="server" DataSource="<%# Item.Property3 %>" ItemType="B">
<ItemTemplate>
<asp:Label Text="<%# Item.Property4 %>" runat="server" />
</ItemTemplate>
</asp:Repeater>
</ItemTemplate>
</asp:Repeater>
Run Code Online (Sandbox Code Playgroud)
我如何从第二个中继器访问Property2?
好吧,通过在嵌套转发器中访问父数据,在HeaderTemplate中,我找到了以下解决方案.它不是最漂亮的,但它有效:
<%# ((Container.Parent.Parent as RepeaterItem).DataItem as A).Property2 %>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4080 次 |
| 最近记录: |