自己写无限极栏目,用了一个精彩的迭代

本文介绍了一种使用HTML动态生成页面并展示层级结构的方法,通过全局变量和函数实现父子元素的递归渲染。

htmlSorts  为全局变量 public string FormSorts(string sortid,string eid)         {             htmlSorts = "<select name=/"sort"+eid+"/"      id=/"sort/" >";             htmlSorts += "<option value=0 >根目录</option>";             FormChildSort("0", "," + sortid + ",");             htmlSorts += "</select>";             return htmlSorts;         }       public void FormChildSort(string id, string sortid)         {             DataTable dtChildSort;             dtChildSort = Modulesql.CreateDataSetaaCH("SELECT * FROM sort  where parentid=" + id + " order by id", "sort").Tables[0];             if (!(dtChildSort.Rows.Count == 0))             {                 for (int i = 0; i < dtChildSort.Rows.Count; i++)                 {                     if (sortid.IndexOf("," + dtChildSort.Rows["id"].ToString() + ",") >= 0)                         htmlSorts = htmlSorts + "<option value=" + dtChildSort.Rows["id"].ToString() + " selected >" + (new string(' ', System.Convert.ToInt32(dtChildSort.Rows["layer"]))) + dtChildSort.Rows["sort"].ToString() + "</option>";                     else                         htmlSorts = htmlSorts + "<option value=" + dtChildSort.Rows["id"].ToString() + " >" + (new string(' ', System.Convert.ToInt32(dtChildSort.Rows["layer"]))) + dtChildSort.Rows["sort"].ToString() + "</option>";                     FormChildSort(dtChildSort.Rows["id"].ToString(), sortid);                 }             }         } 调用方法:FormSorts(选中的id,选中的id);

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值