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

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

你可能感兴趣的:(迭代)