日期:2014-05-17 浏览次数:20540 次
/// <summary> /// 樹形DRP /// </summary> /// <param name="list">ddl控件</param> /// <param name="m_DS">數據源</param> /// <param name="m_Text">默認顯示</param> /// <param name="m_UpFieldId">父ID</param> /// <param name="m_FieldId">ID</param> /// <param name="m_FieldText">顯示內容</param> public static void BindTreeDrp(DropDownList list, System.Data.DataSet m_DS, string m_Text, string m_UpFieldId, string m_FieldId, string m_FieldText) { System.Data.DataTable dt = m_DS.Tables[0]; list.Items.Clear(); if (!string.IsNullOrEmpty(m_Text)) list.Items.Add(new ListItem(m_Text, "")); System.Data.DataRow[] drs = dt.Select(m_UpFieldId + "=0"); foreach (System.Data.DataRow dr in drs) { string bid = dr[m_FieldId].ToString(); string bussesname = dr[m_FieldText].ToString(); list.Items.Add(new ListItem(bussesname, bid)); int chrid = int.Parse(bid); string blank = " "; BindNode(list, m_UpFieldId, m_FieldId, m_FieldText, chrid, dt, blank);//绑定子节点 } } private static void BindNode(System.Web.UI.WebControls.DropDownList list, string m_UpFieldID, string m_FieldID, string m_FieldText, int parentid, System.Data.DataTable dt, string blank) { System.Data.DataRow[] drs = dt.Select(m_UpFieldID + "= " + parentid); foreach (System.Data.DataRow r in drs) { string nodeid = r[m_FieldID].ToString(); StringBuilder text = new StringBuilder(); text.Append(blank); text.Append(r[m_FieldText].ToString()); list.Items.Add(new ListItem(text.ToString(), nodeid)); int sonparentid = System.Int32.Parse(nodeid); StringBuilder blank2 = new StringBuilder(); blank2.Append(blank); blank2.Append(" "); BindNode(list, m_UpFieldID, m_FieldID, m_FieldText, sonparentid, dt, blank2.ToString()); } }
------解决方案--------------------
一个无限递归