加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

asp.net – 中继器中继器

发布时间:2020-12-15 21:09:58 所属栏目:asp.Net 来源:网络整理
导读:我在转发器内有一个转发器。其中父中继器绑定到一个Datatble,它有一个Datatable其中的列。 我想绑定子中继器到父中继器的datarow中的datatable列 这可能吗?我想我可以这样直接在aspx文件像: DataSource =“%#DataBinder.Eval(Container.DataItem,”Prod
我在转发器内有一个转发器。其中父中继器绑定到一个Datatble,它有一个Datatable其中的列。

我想绑定子中继器到父中继器的datarow中的datatable列

这可能吗?我想我可以这样直接在aspx文件像:

DataSource =“<%#DataBinder.Eval(Container.DataItem,”Products“)%>”但它似乎不工作。

解决方法

在父中继器中,将一个方法附加到OnItemDataBound事件,并在该方法中,找到嵌套的重复器和数据绑定它。

示例(.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):

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();
    }
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读