当前位置: 代码迷 >> ASP.NET >> Repeater嵌套子级如何取父级的值
  详细解决方案

Repeater嵌套子级如何取父级的值

热度:770   发布时间:2013-02-25 00:00:00.0
Repeater嵌套子级怎么取父级的值
<Caicai:CRepeater ID="CRepeater1" runat="server">
<ItemTemplate>
<h1><%# Eval("id")%></h1><span><%# Eval("name")%></span>
<Caicai:CRepeater ID="CRepeater2" runat="server">
<ItemTemplate>
<h2><%# Eval("id")%></h2><span><%# Eval("name")%></span>
</ItemTemplate>
</Caicai:CRepeater>
</ItemTemplate>
</Caicai:CRepeater>


子级(CRepeater2)里的<%# Eval("name")%>怎么能取到父级(CRepeater2)的<%# Eval("name")%>

意思就是子级(CRepeater2)里的<%# Eval("name")%>需要显示的数据是父级(CRepeater2)的


求助...


------解决方案--------------------------------------------------------
HTML code
<Caicai:CRepeater ID="CRepeater1" runat="server"> <ItemTemplate> <h1> <%# Eval("id")%> </h1> <span> <%# Eval("name")%> </span> <Caicai:CRepeater ID="CRepeater2" runat="server"> <ItemTemplate> <h2> <%# Eval("id")%> </h2> <span> <%# Eval("name")%> </span> </ItemTemplate> </Caicai:CRepeater> </ItemTemplate> </Caicai:CRepeater>
------解决方案--------------------------------------------------------
推荐非反射
假如你绑定的数据源是 DataTable/DataView/DataSet

<%# ((Container.NamingContainer.NamingContainer as RepeaterItem).DataItem as DataRowView)["name"] %> 

实体类

<%# ((Container.NamingContainer.NamingContainer as RepeaterItem).DataItem as MyEntity).TheNameProperty %>
  相关解决方案