子绑定控件获取父绑定项的值

当绑定控件内嵌套绑定控件时,有时子绑定控件内会需要获取父绑定项的值,获取方法如下:

1.表达式
<%#DataBinder.Eval(Container.Parent.Parent, "DataItem.Name")%>

2.表达式
<%# DataBinder.Eval(((RepeaterItem)Container.Parent.Parent).DataItem, "Name")%>

示例如下:

<asp:Repeater runat="server">
    <HeaderTemplate>
        <table width="100%" border="0" cellspacing="0" cellpadding="0" class="clr_for1">
    </HeaderTemplate>
    <ItemTemplate>
        <tr>
            <td align="center">
                <asp:DataList runat="server" DataSource='<%#Eval("DoorList") %>'  RepeatColumns="4" RepeatDirection="Horizontal">
                    <ItemTemplate>
                        <table >
                            <tr>
                                <td height="20"
        父类:<%# DataBinder.Eval(((RepeaterItem)Container.Parent.Parent).DataItem, "Name")%>                               
    </td>
                  <td height="20">
        名称:<%# DataBinder.Eval(Container.DataItem, "Name")%>
    </td>
                            </tr>
                        </table>
                    </ItemTemplate>
                </asp:DataList>
            </td>
        </tr>
    </ItemTemplate>
    <FooterTemplate>
        </table>
    </FooterTemplate>
</asp:Repeater>


后台代码:
// Category内有List<DoorInfo> DoorList的属性
List<Category> categoryList = doorBLL.GetRecommendList(categoryCount, goodsCount);

rptRecommend.DataSource = categoryList;
rptRecommend.DataBind();

你可能感兴趣的:(获取)