Reputation: 1626
It's possible to use repeater inside the another repeater? How?
my problem is, the back-end can't see the repeater inside the repeater.
FRONT:
<div id="blogright">
<ul class="accordion">
<asp:Repeater ID="parentRep" runat="server">
<ItemTemplate>
<li class="2010">
<a href="blog.aspx?id=<%# Eval("DYear") %>"><%# Eval("DYear") %><span><%# Eval("PCount") %></span></a>
<ul class="sub-menu">
<asp:Repeater ID="childRep" runat="server">
<ItemTemplate>
<li><a href="#"><em><%# Eval("DDay") %></em><%# Eval("DMonth") %><span><%# Eval("ICount") %></span></a></li>
</ItemTemplate>
</asp:Repeater>
</ul>
</li>
</ItemTemplate>
</asp:Repeater>
</ul>
</div>
BACK:
//This is for parentRep
daString = "SELECT datepart(YEAR,BLG_DATE) as DYear,COUNT(BLG_DATE) as PCount FROM [BLG] INNER JOIN [ACC] ON [BLG].ACC_ID=[ACC].ACC_ID WHERE [BLG].ACC_ID='"+userID+"' GROUP BY BLG_DATE";
SqlDataAdapter da2 = new SqlDataAdapter(daString, conn);
DataTable dt2 = new DataTable();
da2.Fill(dt2);
parentRep.DataSource = dt2;
parentRep.DataBind();
//This is for childRep
dt.Clear();
daString = "SELECT DATEPART(DAY,BLG_DATE) as DDay,datename(month,BLG_DATE) as DMonth,DATEPART(YEAR,BLG_DATE) as DYear FROM [BLG] INNER JOIN [ACC] ON [BLG].ACC_ID=[ACC].ACC_ID WHERE [BLG].ACC_ID='"+userID+"' and BLG_DATE like '%"+urlId+"%'";
SqlDataAdapter da3 = new SqlDataAdapter(daString, conn);
DataTable dt3 = new DataTable();
da2.Fill(dt3);
//can't see the childRep here.
Sorry for my English.
Upvotes: 1
Views: 527
Reputation: 161
You can get a reference to the child Repeater and bind data to it in the ItemDataBound event this way:
protected void parentRep_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
if (args.Item.ItemType == ListItemType.Item || args.Item.ItemType == ListItemType.AlternatingItem)
{
Repeater childRepeater = (Repeater)e.Item.FindControl("childRep");
childRepeater.ItemDataBound += new RepeaterItemEventHandler(childRepeater_ItemDataBound);
childRepeater.ItemCommand += new RepeaterCommandEventHandler(childRepeater_ItemCommand);
childRepeater.DataSource = dt3; //dt3 is the DataTable from your code sample
childRepeater.DataBind();
}
}
Additionally, there are some very thorough answers in this thread: Repeater in Repeater
Upvotes: 2