自己寫無限極欄目,用了一個精彩的迭代

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

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章