I would add a DataBinding event to the repeater itself:
<asp:Repeater ID="yourRepeater" runat="server" OnDataBinding="yourRepeater_DataBinding">
Then just implement it:
protected void yourRepeater_DataBinding(object sender, System.EventArgs e)
{
Repeater rep = (Repeater)(sender);
int someIdFromParentDataSource = (int)(Eval("ParentID"));
// Assuming you have a function call `GetSomeData` that will return the data you
// want to bind to your child repeater.
rep.DataSource = GetSomeData(int);
rep.DataBind();
}
I prefer to do it at the control level instead of the ItemDataBound
level so that if you ever have to remove controls or items within your templates you don't have to worry about looking for code in the parent controls that use it. It get's all localize witht he control itself. Plus you never have to do a FindControl
.
If you want to replace a control in the future you can just delete it and your code will still work since it is all self contained. Using the ItemDataBound
would cause your code to still compile but crash or act unexpectedly at runtime because of it's reliance on child controls.