I figured this out; just took a bit to get back in the ole' ASP.NET server controls mode ;)
The idea is to still use the ItemDataBound
event, but inspect for both Item
and AlternatingItem
along with casting the DataItem
to the CustomerObject
. Then I proceeded to use the original collection bound to the DataList
I had stored in session and use a quick Find()
to get the proper object pulled back out. Once that's narrowed down, I can use it's .Orders
collection to bind to the inner DataList.DataSource
property. It works like a charm:
protected void ui_dlst_ETLMainInformation_ItemDataBound(object sender, DataListItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
Customer c = e.Item.DataItem as Customer;
DataList innerDataList = e.Item.FindControl("innerDataListControl") as DataList;
List<Customers> customers = ((IList)Session["CustomersCollection"]).Cast<Customers>().ToList();
Customer customer = customers.Find(ct => ct.ID == c.ID);
innerDataList.DataSource = customer.Orders;
innerDataList.DataBind();
}
}