前台代碼部分:
復制代碼 代碼如下:
<asp:repeater runat="server" id="repeater1" OnItemDataBound="function2">
<itemtemplate>
<asp:repeater runat="server" id="repeater2">
<itemtemplate>
</itemtemplate>
</asp:repeater>
<itemtemplate>
</asp:repeater>
後台代碼部分:
復制代碼 代碼如下:
private void function1()
{
repeater1.datasource = datatable;
repeater1.databind();
}
private void function2(object sender,repeateritemeventargs e)
{
//判斷裡層repeater處於外層repeater的哪個位置(alternatingitemtemplate,footertemplate,headertemplate,itemtemplate,separatortemplate)
if(e.item.itemtype == listitemtype.item || e.item.itemtype == listitemtype.alternatingitem)
{
repeater rpt = e.item.findcotrol("repeater2") as repeater; //找到裡層的repeater對象
datarowview row = (datarowview)e.item.dataitem; //找到分類repeater關聯的數據項
int typeid = convert.toint32(row["id"]); //獲取填充子類的id
rpt.datasource = datatable;
rpt.databind();
}
}