Repeater nesting method, which is quite simple
First, the ASPX page
<Asp: repeater id = "RP" runat = "server">
<Itemtemplate>
<% # Eval ("ID") %>
<Asp: repeater id = "RP1" runat = "server" datasource = '<% # getdata (eval ("ID") %>'>
<Itemtemplate>
<% # Eval ("name") %> <br/>
</Itemtemplate>
</ASP: repeater>
<Br/>
</Itemtemplate>
</ASP: repeater>
The key is <asp: repeater id = "RP1" runat = "server" datasource = '<% # getdata (eval ("ID") %>'>
Getdata is a UDF with the following prototype:
Protected datatable getdata (Object OBJ)
{
Datatable dt = new datatable ();
// Do something here
Return DT;
}
The complete code is as follows: aspx
<% @ Page Language = "C #" autoeventwireup = "true" codefile = "test. aspx. cs" inherits = "test" %>
<% @ Import namespace = "system. Data" %>
<! Doctype HTML public "-// W3C // dtd xhtml 1.0 transitional // en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd">
<HTML xmlns = "http://www.w3.org/5o/xhtml">
<Head runat = "server">
<Title> NID's blog http://www.ljnid.cn </title>
</Head>
<Body>
<Form ID = "form1" runat = "server">
<Div>
<Asp: repeater id = "RP" runat = "server">
<Itemtemplate>
<% # Eval ("ID") %>
<Asp: repeater id = "RP1" runat = "server" datasource = '<% # getdata (eval ("ID") %>'>
<Itemtemplate>
<% # Eval ("name") %> <br/>
</Itemtemplate>
</ASP: repeater>
<Br/>
</Itemtemplate>
</ASP: repeater>
</Div>
</Form>
</Body>
</Html>
Aspx. CS File
Using system;
Using system. Data;
Using system. configuration;
Using system. collections;
Using system. Web;
Using system. Web. Security;
Using system. Web. UI;
Using system. Web. UI. webcontrols;
Using system. Web. UI. webcontrols. webparts;
Using system. Web. UI. htmlcontrols;
Public partial class test: system. Web. UI. Page
{
Protected void page_load (Object sender, eventargs E)
{
Datatable dt = new datatable ();
DT. Columns. Add ("ID ");
For (INT I = 0; I <4; I ++)
{
Datarow DR = DT. newrow ();
Dr ["ID"] = I;
DT. Rows. Add (DR );
}
RP. datasource = DT;
RP. databind ();
}
Protected datatable getdata (Object OBJ)
{
Datatable dt = new datatable ();
DT. Columns. Add ("name ");
For (INT I = 0; I <10; I ++)
{
Datarow DR = DT. newrow ();
Dr ["name"] = "name _" + OBJ + "_" + I;
DT. Rows. Add (DR );
}
Return DT;
}
}