![](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
1 public partial class _Default : System.Web.UI.Page 2 { 3 List<ModelsInfo> list = Models.GetItems(); //获取该表中全部信息 4 protected void Page_Load(object sender, EventArgs e) 5 { 6 7 if (!IsPostBack) 8 { 9 loadData(); //加载数据 10 } 11 } 12 /// <summary> 13 /// 加载数据 14 /// level深度 15 /// </summary> 16 public void loadData() 17 { 18 DropDownList1.Items.Clear(); //清除 19 DropDownList1.Items.Add(new ListItem("全部","0")); 20 string str = "+"; 21 //根据条件对信息进行筛选 22 List<ModelsInfo> temp = list.FindAll(delegate(ModelsInfo m) { 23 return m.Level == 1; 24 }); 25 //循环所有分类级 26 foreach(ModelsInfo info in temp) 27 { 28 DropDownList1.Items.Add(new ListItem(str+info.Model_name,info.Id.ToString())); 29 loadSunData(info,ref str); 30 } 31 DropDownList1.DataBind(); 32 } 33 /// <summary> 34 /// 递归 35 /// </summary> 36 public void loadSunData(ModelsInfo info1,ref string strs) 37 { 38 List<ModelsInfo> list1 = list.FindAll(delegate(ModelsInfo m1) { 39 return m1.Sun_id == info1.Id; 40 }); 41 foreach(ModelsInfo temp1 in list1) 42 { 43 if(temp1.Sun_id==info1.Id){ 44 strs = "+" + strs; 45 DropDownList1.Items.Add(new ListItem(strs+temp1.Model_name, temp1.Id.ToString())); 46 loadSunData(temp1,ref strs); 47 } 48 strs = "+"; 49 } 50 } 51 52 }