下面是从数据库的两个表找出数据并绑定的,但不是用递归
protected void Page_Load(object sender, EventArgs e)
    {
      if (!IsPostBack)
        {
            run(TreeView1.Nodes, "0");
        }
    }public void run(TreeNodeCollection nd, string sname)
    {
        string id;
        if (Request["id"] != null)
        {
            id = Request.QueryString["id"].ToString();
        }
        else
        {
            id = "";
        }
        DataSet ds = new DataSet();
        ds = DB.go("select cname,tu,od,other from max_type order by od desc");
        if (ds.Tables[0].Rows.Count > 0)
        {
            foreach (DataRow dr0 in ds.Tables[0].Rows)
            {
                TreeNode tn = new TreeNode();
                tn.Text = (dr0["cname"].ToString());                if (id == dr0["other"].ToString())
                {
                    tn.Expanded = true;
                }
                else
                {
                    tn.Expanded = false;
                }
                tn.ImageUrl = "images/tree/" + dr0["tu"].ToString();
                //
                
                nd.Add(tn);
                DataSet ds1 = new DataSet();
                ds1 = DB.go("select cname from small_type where max_type='" + tn.Text + "'");
                if (ds1.Tables[0].Rows.Count > 0)
                {
                    tn.SelectAction = TreeNodeSelectAction.Expand;
                    foreach (DataRow dr1 in ds1.Tables[0].Rows)
                    {
                        TreeNode tn1 = new TreeNode();
                        tn1.Text = (dr1["cname"].ToString());
                        tn1.NavigateUrl = "more.aspx?id=" + dr0["other"].ToString() + "&idd=" +Server.UrlEncode(tn1.Text);
                        tn1.ImageUrl = "images/2.gif";
                        tn.ChildNodes.Add(tn1);
                    }
                }
                else
                {
                        tn.NavigateUrl = "more.aspx?id=" + dr0["other"].ToString();
                }
            }
        }
    }