数据表里有id,和pid两例
private void bindtree()
{
TreeView1.Nodes.Clear();
TreeNode root=new TreeNode();
root.Expanded=true;
root.Text="字典维护";
root.NodeData="0";
this.TreeView1.Nodes.Add(root);
creattree(0,root);
}
public void creattree(int fid,TreeNode parentnode)
{
DataTable dt=new DataTable();
dt=sj.db.GetDataTable("select * from 数据表");
DataRow[] drs=dt.Select("pid="+fid);
foreach(DataRow row in drs)
{
TreeNode tempnode=new TreeNode();
tempnode.Text=row["mingcheng"].ToString();
tempnode.NodeData=row["id"].ToString();
parentnode.Nodes.Add(tempnode);
creattree(Convert.ToInt32(row["id"]),tempnode);
}
}