public void GetSubClass(DataSet ds, int level, string parentid, string sign) { char nbsp = (char)0xA0; string lp = ""; DataRow[] drr2 = ds.Tables[0].Select(" parentId='" + parentid + "' "); int index = 0; if (level == 0) { foreach (DataRow dr in drr2) { index++; lp = dr["name"].ToString().Insert(0, "|___"); DropDownList1.Items.Add(new ListItem(lp.PadLeft((lp.Length + 2), nbsp), dr["id"].ToString())); if (index != drr2.Length) GetSubClass(ds, level+1, dr["id"].ToString(), "1"); else GetSubClass(ds, level+1, dr["id"].ToString(), "0"); } } else { DataRow[] drr3 = ds.Tables[0].Select(" parentid='" + parentid + "' "); string[] fg = { "," }; string ls = ""; if (drr3 != null && drr3.Length > 0) { foreach (DataRow dr2 in drr3) { int lslevel = level; index++; foreach (string ss in sign.Split(fg, StringSplitOptions.RemoveEmptyEntries)) { if (lslevel == level) { if (ss == "1") { lp = "|"; lp = lp.PadLeft((lp.Length + 2), nbsp); lp = lp.PadRight((lp.Length + 10), nbsp); } else { lp = " "; lp = lp.PadLeft((lp.Length + 2), nbsp); lp = lp.PadRight((lp.Length + 10), nbsp); } lslevel--; if (lslevel == 0) lp = lp + "|___" + dr2["name"].ToString(); } else { if (ss == "1") { lp += "|"; lp = lp.PadRight((lp.Length + 10), nbsp); } else { lp = lp.PadRight((lp.Length + 11), nbsp); } lslevel--; if (lslevel == 0) lp = lp + "|___" + dr2["name"].ToString(); } } if (index != drr3.Length) { DropDownList1.Items.Add(new ListItem(lp, dr2["id"].ToString())); GetSubClass(ds, level+1, dr2["id"].ToString(), sign + ",1"); } else { DropDownList1.Items.Add(new ListItem(lp, dr2["id"].ToString())); GetSubClass(ds, level+1, dr2["id"].ToString(), sign + ",0"); } } } } } protected void qxa() { Maticsoft.BLL.webClass classwc = new Maticsoft.BLL.webClass(); DataSet ds; //string lp=""; //int index = 0; //char nbsp = (char)0xA0; ds = classwc.GetList(" "); DropDownList1.Items.Clear(); DropDownList1.Items.Add(new ListItem("根栏目", "0")); if (ds != null && ds.Tables.Count > 0 && ds.Tables[0] != null && ds.Tables[0].Rows.Count > 0) { //DataRow[] drr2 = ds.Tables[0].Select(" parentId=0 "); GetSubClass(ds, 0, "0", ""); //foreach (DataRow dr in drr2) //{ // index++; // lp = dr["name"].ToString().Insert(0, "|___"); // DropDownList1.Items.Add(new ListItem(lp.PadLeft((lp.Length + 2),nbsp), dr["id"].ToString())); // DataRow[] drr3 = ds.Tables[0].Select(" parentid=" + dr["id"].ToString() + " "); // if (drr3 != null && drr3.Length > 0) // { // foreach (DataRow dr2 in drr3) // { // if (index != drr2.Length) // { // lp = "|"; // lp = lp.PadLeft((lp.Length + 2), nbsp); // lp = lp.PadRight((lp.Length + 8), nbsp); // lp = lp + "|___" + dr2["name"].ToString(); // } // else // { // lp = " "; // lp = lp.PadLeft((lp.Length + 2), nbsp); // lp = lp.PadRight((lp.Length + 8), nbsp); // lp = lp + "|___" + dr2["name"].ToString(); // } // DropDownList1.Items.Add(new ListItem(lp, dr2["id"].ToString())); // } // } //} } }