如何在嵌套的datarepeaters中显示连接和重复的数据?

时间:2015-02-10 18:24:33

标签: c# repeater

我想在嵌套数据中继器中显示相互关联的数据,但是当我通过拖放操作时,只有第一级数据中继器工作,剩下的不会显示任何内容。

有什么想法怎么做? 以下是我想要显示的示例:

1 个答案:

答案 0 :(得分:0)

您可以在外部使用事件处理程序“itemdatabound”来每次填充内部Repeater。这里和简短的例子:

在.aspx文件中:

<asp:Repeater ID="Repeater_Parent" runat="server" onitemdatabound="Repeater_Parent_ItemDataBound">
    <!-- //Show data for the Repeater_Parent -->
    <asp:Repeater ID="Repeater_Child" runat="server">
        <!-- //Show data for the Repeater_Child -->
    </asp:Repeater> 
</asp:Repeater>

在.cs文件中:

 protected void Repeater_Parent_ItemDataBound(object source, RepeaterItemEventArgs e) {
    //Saves the repeater_parent as repeaterSource
    RepeaterItem repeaterSource = e.Item;
    //Find the chhild Repeater
    Repeater childRepeater = repeaterSource.FindControl("Repeater_Child") as Repeater;
    DataSet ds = new DataSet();

    //Here fill the ds with some kind of data you want to display in the child Repeater

    //Bind ds to Child repeater
    childRepeater.DataSource = ds;
    childRepeater.DataBind();
}