TreeView递归 加载
zuid zupth zuname adduser1000 0 省 0
10000001 1000 测试 0
100000010001 10000001 测试组 0
100000010002 10000001 我爱你了 0
100000010003 10000001 我的小组 _54H11169O
1000000100030001 100000010003 我的小小组 _54H11169O
1000000100030002 10000001 测试组小组 _54H11169O
10000002 1000 省下下的组 _LPD20F5P3
100000020001 10000002 省下下的组的组 _LPD20F5P3
100000020002 10000002 省下组租二 _LK1G8NME2
NULL NULL NULL NULL
现在需要递归加载TreeView value为zuid text为zuname --------------------编程问答-------------------- 以前.net 1.1下用的树形菜单递归算法,你可以参考下。
/// <summary>
/// 递归构建节点树
/// </summary>
private void CreateNode(string id,TreeNode td)
{
Microsoft.Web.UI.WebControls.TreeNode tempNode=null;
string selectString=null;
string strNodeText=null;
string strChildId=null;
selectString="Menu_Parent=" + id + "";
DataRow[] dataRows = treeDataSet.Tables["menuTable"].Select(selectString); //搜索当前节点的所有子节点
foreach(DataRow dr in dataRows)
{
tempNode = new Microsoft.Web.UI.WebControls.TreeNode();
strNodeText = dr["Menu_Name"].ToString();
strChildId = dr["id"].ToString();
tempNode.Text = strNodeText;
td.Nodes.Add(tempNode); //添加子节点
CreateNode(strChildId,tempNode);
}
}
--------------------编程问答-------------------- public void AddChildNode(DataView dr, TreeNode node,string sql,string yname)
{
dr = getview(sql);
dr.RowFilter = "FatherTreeID = '" + node.Value + "'";//过滤
foreach (DataRowView drv1 in dr)
{
TreeNode ChildNode = new TreeNode();
ChildNode.Text = drv1["TreeName"].ToString();//
ChildNode.Value = drv1["TreeID"].ToString();
ChildNode.Expanded = false;//展开属性为FALSE
node.ChildNodes.Add(ChildNode);//递归循环插入子节点
AddChildNode(dr, ChildNode, sql,yname);//递归调用自己
}
} --------------------编程问答-------------------- 仅供参考
/// <summary>
/// 递归加载树数据
/// </summary>
/// <param name="parentID">根结点的父节点</param>
/// <param name="pNode"></param>
private void AddTree(int parentID, TreeNode pNode)
{
DataTable dt = (DataTable)ViewState["functionTable"];
DataView dvTree = new DataView(dt);
dvTree.Sort = "F_Sort";
//过滤ParentID,得到当前的所有子节点
dvTree.RowFilter = "[F_Parent_ID] = " + parentID;
if (dvTree.Count == 0)
{
return;
}
foreach (DataRowView Row in dvTree)
{
TreeNode Node = new TreeNode();
if (pNode == null)
{
//添加根节点
Node.Text = Row["F_Function_Name"].ToString();
Node.Value = Row["F_Function_ID"].ToString();
this.TreeViewControl.Nodes.Add(Node);
Node.ShowCheckBox = true;
Node.Expanded = true;
Node.SelectAction = TreeNodeSelectAction.None;
AddTree(Int32.Parse(Row["F_Function_ID"].ToString()), Node); //再次递归
}
else
{
//添加当前节点的子节点
Node.Text = Row["F_Function_Name"].ToString();
Node.Value = Row["F_Function_ID"].ToString();
Node.SelectAction = TreeNodeSelectAction.None;
pNode.ChildNodes.Add(Node);
Node.ShowCheckBox = true;
Node.Expanded = true;
AddTree(Int32.Parse(Row["F_Function_ID"].ToString()), Node); //再次递归
}
}
}
--------------------编程问答-------------------- up
补充:.NET技术 , ASP.NET