Nested grid woes
I've done nested grids before, something like this:
<asp:Repeater ID="CatRepeater" Runat="Server">
<ItemTemplate>
<p><%# Eval("Name") %></p>
<asp:GridView ID="ForumGrid" Runat="Server" AutoGenerateColumns="true" AllowPaging="false"
DataSource='<%# new Category(Convert.ToInt32(Eval("CategoryID"))).GetForumCollection(false, false) %>'>
</asp:GridView>
</ItemTemplate>
</asp:Repeater>
I tried to do it in a more event driven manner today like this:
<script runat="server">
void Page_Load(object sender, EventArgs e)
{
CategoryCollection c = Category.GetCategories(false);
c.Insert(0, new Category(0));
CatRepeater.DataSource = c;
CatRepeater.DataBind();
}
void CatRepeater_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
GridView g = (GridView)e.Item.FindControl("ForumGrid");
ForumCollection f = ((Category)e.Item.DataItem).GetForumCollection(false, false);
g.DataSource = f;
g.DataBind();
Trace.Warn(g.Rows.Count.ToString());
Trace.Warn(f.Count.ToString());
}
</script>
...
<asp:Repeater ID="CatRepeater" Runat="Server" OnItemDataBound="CatRepeater_ItemDataBound">
<ItemTemplate>
<p><%# Eval("Name") %></p>
<asp:GridView ID="ForumGrid" Runat="Server" AutoGenerateColumns="true" AllowPaging="false">
</asp:GridView>
</ItemTemplate>
</asp:Repeater>
Here's what I don't get. In the two traces of the binding handler, the rows in the grid return 0 after databinding, yet the ForumCollection does indeed show the actual count. Am I missing something?
This is actually going to change later on, because I don't want to be making multiple hits to the data every time, but I'm experimenting with something else.