表结构:ID(int),ParentID(int), ConText(varchar(50)), depth(varchar(100)),image(varchar(100)), eimage(varcahr(100)),
////////////
///
// 递归添加树的节点
public void AddTree(int ParentID,TreeNode pNode)
{
DataSet ds=(DataSet) this.ViewState["ds"];
DataView dvTree = new DataView(ds.Tables[0]);
//过滤ParentID,得到当前的所有子节点
dvTree.RowFilter = "[PARENTID] = " + ParentID;
foreach(DataRowView Row in dvTree)
{
TreeNode Node=new TreeNode() ;
if(pNode == null)
{ //'?添加根节点
TreeView1.Nodes.Add(Node);
Node.Expanded = true;
}
else
{ //添加当前节点的子节点
pNode.Nodes.Add(Node);
Node.Expanded = false;
}
Node.Text = Row["ConText"].ToString();
AddTree(Int32.Parse(Row["ID"].ToString()), Node);//递归
Node.Target = "main";
Node.NavigateUrl = Row["depth"].ToString();
Node.ImageUrl = Row["image"].ToString() ;
Node.ExpandedImageUrl = Row["eimage"].ToString();
}
}