private void InitTree(TreeNodeCollection Nds, string pid, DataTable dt, string id, string name, string urlname, string parentID)
{
TreeNode tmpNd; //递归寻找子节点
DataRow[] rows = dt.Select(dt.Columns["pid"].ColumnName + "='" + parentID + "'");
foreach (DataRow row in rows)
{
tmpNd = new TreeNode();
tmpNd.Value = row["id"].ToString();
tmpNd.Text = row["name"].ToString();
if (urlname != null)
tmpNd.NavigateUrl = row["urlname"].ToString();
Nds.Add(tmpNd);
InitTree(tmpNd.ChildNodes, pid, dt, id, name, urlname, tmpNd.Value);
}
}
表结构:
tree(id,name,url,pid)