private void LoadTree(TreeNode ParentID, string CID)
{
string sql = "";
//定义SQL查询语句
sql = "Select ID , Name ,ParID From HS_WL_Department Where ParID =" + CID ;
//根据SQL语句填充DataSet
DataSet ds=new DataSet();
DataTool dtool = new DataTool();
dtool.Fill(sql,"Dept",ds);
DataView dview = new DataView(ds.Tables["Dept"]);
//针对每一行进行操作,生成TreeNode并添加到TreeView控件中,并针对每一项进行递归调用
foreach (DataRowView dvrow in dview)
{
TreeNode ChildNode = new TreeNode();
ChildNode.Target = "content_2";
ChildNode.ImageUrl = "../../../common_images/baseinfo/depac.gif";
ChildNode.Text = dvrow[1].ToString();
ParentNode.Nodes.Add(ChildNode);
LoadTree(ChildNode, decimal.Parse(dvrow[0].ToString()));
}
}
主要的就是通过对过程LoadTree(TreeNode ParentID, string CID) 的递归调用实现的!