Nested repeater sample share
- 2020-12-13 18:57:20
- OfStack
Foreground code:
<asp:repeater runat="server" id="repeater1" OnItemDataBound="function2">
<itemtemplate>
<asp:repeater runat="server" id="repeater2">
<itemtemplate>
</itemtemplate>
</asp:repeater>
<itemtemplate>
</asp:repeater>
Background code part:
private void function1()
{
repeater1.datasource = datatable;
repeater1.databind();
}
private void function2(object sender,repeateritemeventargs e)
{
// Judge li repeater In the outer repeater Which location of ( alternatingitemtemplate,footertemplate,headertemplate,itemtemplate,separatortemplate )
if(e.item.itemtype == listitemtype.item || e.item.itemtype == listitemtype.alternatingitem)
{
repeater rpt = e.item.findcotrol("repeater2") as repeater; // Find the inner one repeater object
datarowview row = (datarowview)e.item.dataitem; // Find a classification repeater Associated data item
int typeid = convert.toint32(row["id"]); // Gets to populate a subclass id
rpt.datasource = datatable;
rpt.databind();
}
}