直放站直放站 [英] Repeater in Repeater

查看:161
本文介绍了直放站直放站的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个中继器内的中继器。当母体中继器绑定到 Datatble 这在它有一个数据表列。

I have a repeater inside a repeater. Where the parent repeater is bound to a Datatble which has a column with a Datatable in it.

我想给孩子直放站绑定到父中继器的数据行的数据表列

I would like to bind the child repeater to the datatable column in the parent repeater's datarow

这可能吗?我想我可以直接做到这一点, ASPX 文件,如:

Is this possible? i was thinking i could do this directly in the aspx file like:

数据源=<%#DataBinder.Eval的(的Container.DataItem,产品)%GT;,但它似乎没有工作。

DataSource="<%# DataBinder.Eval(Container.DataItem, "Products")%>" but it doesn't seem to work.

推荐答案

在父中继器,附加一个方法的OnItemDataBound事件,并在该方法中,发现将其绑定嵌套的中继器和数据。

In the parent repeater, attach a method to the OnItemDataBound event and in the method, find the nested repeater and data bind it.

示例(的.aspx):

Example (.aspx):

<asp:Repeater ID="ParentRepeater" runat="server" OnItemDataBound="ItemBound">
    <ItemTemplate>
        <!-- Repeated data -->
        <asp:Repeater ID="ChildRepeater" runat="server">
            <ItemTemplate>
                <!-- Nested repeated data -->
            </ItemTemplate>
        </asp:Repeater>
    </ItemTemplate>
</asp:Repeater>

示例(的.cs):

Example (.cs):

protected void Page_Load(object sender, EventArgs e)
{
    if (!IsPostBack)
    {
        ParentRepeater.DataSource = ...;
        ParentRepeater.DataBind();
    }
}

protected void ItemBound(object sender, RepeaterItemEventArgs args)
{
    if (args.Item.ItemType == ListItemType.Item || args.Item.ItemType == ListItemType.AlternatingItem)
    {
        Repeater childRepeater = (Repeater)args.Item.FindControl("ChildRepeater");
        childRepeater.DataSource = ...;
        childRepeater.DataBind();
    }
}

这篇关于直放站直放站的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆