I have a 2 tables in SQL Server. One table has a list of all superheros and the other table is a list of abilities. Currently at runtime the child repeater gets all items in the table when it should only get the items pertaining to the parent table. On my aspx page I have a nested repeater like so:
<asp:Repeater id="rptHero" runat="server" DataSourceID="sdsHeros" OnItemDataBound="rptHero_ItemDataBound">
<ItemTemplate>
<table>
<tr>
<td> <%# Eval("HeroName")%> </td>
<asp:Repeater id="rptAbility" runat="server" >
<ItemTemplate>
<tr>
<td> <%# Eval("AbilityName")%> </td>
</tr>
</ItemTemplate>
</asp:Repeater>
</tr>
</table>
<p> </p>
</ItemTemplate>
</asp:Repeater>
<asp:SqlDataSource ID="sdsHero" runat="server" ConnectionString="<%$ ConnectionStrings:SiteSqlServer2 %>"
SelectCommand="SELECT [num], [HeroName] FROM [Super_Heros]"></asp:SqlDataSource>
<asp:SqlDataSource ID="sdsAbility" runat="server" ConnectionString="<%$ ConnectionStrings:SiteSqlServer2 %>"
SelectCommand="SELECT [num], [AbilityName] FROM [Super_Ability]"></asp:SqlDataSource>
And in my code behind I have:
protected void rptHero_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
DataRowView row = (DataRowView)e.Item.DataItem;
Repeater nestedRepeater = e.Item.FindControl("rptAbility") as Repeater;
nestedRepeater.DataSource = sdsAbility;
nestedRepeater.DataBind();
}
}
Following Example 1 and Example 2 posted by our fine patrons here on Stack Overflow this should work however, I think the part I am skipping over where the [num]
of the parent repeater gets compared to the [HeroID]
of the child repeater as in a SQLJoin.