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

来源:互联网 发布:js遍历object对象 编辑:程序博客网 时间:2024/05/16 07:44

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);

原创粉丝点击