如何在嵌套数据中继器中显示连接和重复的数据?
How to display joined and repeated data in nested datarepeaters?
我想在嵌套的数据转发器中显示一个相互关联的数据,但是当我通过拖放操作时,只有一级数据转发器工作,其余的不显示任何内容。
知道怎么做吗?
这是我要显示的示例:
你可以在外部使用事件处理程序"onitemdatabound"来每次填充内部中继器。这里和简短的例子:
在 .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();
}
我想在嵌套的数据转发器中显示一个相互关联的数据,但是当我通过拖放操作时,只有一级数据转发器工作,其余的不显示任何内容。
知道怎么做吗? 这是我要显示的示例:
你可以在外部使用事件处理程序"onitemdatabound"来每次填充内部中继器。这里和简短的例子:
在 .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();
}