递归绑定

mac2022-06-30  73

private void DropDownListBind() { ddl.Items.Clear(); dt = Productmanage.Instance.GetAllProCate(); if (dt != null) bindTree(dt, 0, 0); ddl.Items.Insert(0, new ListItem("所有分类", "0")); } private void bindTree(DataTable dt, int parentId, int dep) { dep++; foreach (DataRow dr in dt.Select("parent_cid=" + parentId)) { ddl.Items.Add(new ListItem(showNull(dep) + dr["name"], dr[0].ToString())); bindTree(dt, Convert.ToInt32(dr["cid"]), dep); } } private string showNull(int dep) { string str = null; for (int i = 1; i < dep; i++) str += " "; return str + "|-"; }

 

转载于:https://www.cnblogs.com/daixingqing/archive/2012/11/13/2768417.html

相关资源:WinForm_TreeView递归绑定Demo
最新回复(0)