using System;
using ;
using ;
using ;
using ;
using ;
using ;
using ;
using ;
namespace WebApplication3 {
public partial class WebForm1: {
protected void Page_Load(object sender, EventArgs e) {
int id = Convert.ToInt32(Request["parentID"]);
GetXML(id);
}
public IList < Product > GetList() {
return new List < Product > () {
new Product() {
Id = 1,
ParentId = 0,
HasChild = 1,
Name = "aaaaa"
},
new Product() {
Id = 2,
ParentId = 1,
HasChild = 1,
Name = "bbbb1"
},
new Product() {
Id = 3,
ParentId = 2,
HasChild = 0,
Name = "ccccc2"
},
new Product() {
Id = 4,
ParentId = 2,
HasChild = 0,
Name = "ddddd3"
},
new Product() {
Id = 5,
ParentId = 1,
HasChild = 0,
Name = "eeeeee4"
},
new Product() {
Id = 6,
ParentId = 3,
HasChild = 0,
Name = "ffffff5"
},
new Product() {
Id = 7,
ParentId = 4,
HasChild = 0,
Name = "ggggggg6"
},
new Product() {
Id = 8,
ParentId = 7,
HasChild = 0,
Name = "hhhhhhh7"
},
new Product() {
Id = 9,
ParentId = 0,
HasChild = 0,
Name = "jjjjjjj8"
},
new Product() {
Id = 10,
ParentId = 0,
HasChild = 0,
Name = "yyyyyyyy9"
}
};
} /// <summary>
/// Read the child node through the parent node and splice it into xml to the front desk
/// </summary>
/// <param name="parentId"></param>
public void GetXML(int parentId) {
List<Product> list = GetList().Where(x => == parentId).ToList();
XElement xElement = new XElement("textTree");
foreach (Product p in list) {
(new XElement("value", new XAttribute("id", ),));
}
("d:\\");
XmlDocument xdocument = new XmlDocument();
("d:\\");
= "text/xml";
();
();
}
}
public class Product {
public int Id{set;get;}
public int ParentId{set;get;}
public int HasChild{set;get;}
public string Name{set;get;}
}}
The idea is very simple. The background uses xml to send it to the front desk and receives and processes splicing ul through jquery.
Li principle (using the method of nesting < ul > in < li >, locally read all direct child nodes under a node. Each time you click to read, if you read it, you will enter the GetDisplayOrNot() method to determine the display and hide nodes) html code: < body > <form id = "form1"
runat = "server" > <input type = "button"
value = "text"
onclick = "LoadXml(0)" / ><div id = "root" > </div>
</form >
</body>