<Asp: repeater id = "repeater1" runat = "server" onitemdatabound = "repeaterincluitemdatabound">
<Headertemplate> <ul>
<Itemtemplate>
<Li> <% # eval ("cate_name") %>
<Asp: repeater id = "repeater2" runat = "server">
<Headertemplate> <ul>
<Itemtemplate>
<Li> <% # eval ("art_title") %> </LI>
</Itemtemplate>
<Footertemplate> </ul> </footertemplate>
</ASP: repeater>
</LI>
</Itemtemplate>
<Footertemplate> </ul> </footertemplate>
</ASP: repeater>
BackendCode:
Protected void page_load (Object sender, eventargs E)
{
If (! Ispostback)
{
Using (sqlconnection conn = new sqlconnection ())
{
Conn. connectionstring = configurationmanager. connectionstrings ["testdbconnectionstring"]. connectionstring;
Conn. open ();
Using (sqldataadapter da = new sqldataadapter ("select * from category", Conn ))
{
Dataset DS = new dataset ();
Da. Fill (DS );
Repeater1.datasource = Ds;
Repeater1.databind ();
}
}
}
}
Protected void repeaterincluitemdatabound (Object sender, repeateritemeventargs E)
{
If (E. Item. itemtype = listitemtype. Item | E. Item. itemtype = listitemtype. alternatingitem)
{
Repeater rep = E. Item. findcontrol ("repeater2") as repeater;
Datarowview rowv = (datarowview) E. Item. dataitem;
Int cate_id = convert. toint32 (rowv ["cate_id"]);
Using (sqlconnection conn = new sqlconnection ())
{
Conn. connectionstring = configurationmanager. connectionstrings ["testdbconnectionstring"]. connectionstring;
Conn. open ();
Using (sqldataadapter da = new sqldataadapter ("select * from article where owner_id =" + cate_id, Conn ))
{
Dataset DS = new dataset ();
Da. Fill (DS );
Rep. datasource = Ds;
Rep. databind ();
}
}
}
}
The nesting of two repeater, which is associated with the nested part by ID, and the output is as follows: