Preview:
Database Structure:
Id (int) classname (string) parentid (int) sort (int for display and sorting)
1 home 0 1
2 appliances 0 2
3 sofa 1 1
4... 3 1
...
10... Red 4 1
Note:
Parentid parent node ID
Sort is used to hide, display, and sort data.
Front-end:
<Asp: Repeater ID = "rep" runat = "server" onitemdatabound = "rep_ItemDataBound">
<HeaderTemplate> </HeaderTemplate>
<ItemTemplate> </ItemTemplate>
<FooterTemplate> </FooterTemplate>
</Asp: Repeater>
Background:
Code Public partial class recursion 2: System. Web. UI. Page
{
Public List <cmodel> list;
Protected void Page_Load (object sender, EventArgs e)
{
If (! IsPostBack)
{
Rules r = new rules ();
List = r. getlist (); // read the database
This. rep. DataSource = list. Where (x => x. parentid = 0). ToList (); // LINQ2OBJECT
This. rep. DataBind ();
}
}
Protected void rep_ItemDataBound (object sender, RepeaterItemEventArgs e)
{
If (e. Item. ItemType = ListItemType. Header)
{
Literal l = new Literal ();
L. ID = "ul ";