无限循环treeview

#region 无限循环treeview
    private void addNode(string ParentID, TreeNode pNode)
    {
        //DataSet ds = (DataSet)this.ViewState["ds "];
        dt=DataBase.dt("select * from mail_department");
        DataView dvTree = new DataView(dt);
        dvTree.RowFilter = " fid= '" + ParentID + "' ";
        foreach (DataRowView drv in dvTree)
        {
            TreeNode node = new TreeNode();
            if (pNode == null)
            {
                node.Text = drv["departmentname"].ToString();
                this.TreeView1.Nodes.Add(node);
                node.Expanded = true;
                node.NavigateUrl = "user.aspx?nid=" + drv["nid"].ToString().Trim();
                node.Target = "main2";
                int n = Convert.ToInt32(drv["nid"].ToString());
                node.Value = drv["nid "].ToString();
                this.addNode(drv["nid "].ToString(), node);
            }
            else
            {
                node.Text = drv["departmentname"].ToString();
                pNode.ChildNodes.Add(node);
                node.Expanded = false;
                //node.NavigateUrl   =   drv[ "URL "].ToString(); 
                node.NavigateUrl = "user.aspx?nid="+ drv["nid"].ToString().Trim();
                node.Target = "main2";
                node.Value = drv["nid"].ToString();
                this.addNode(drv["nid"].ToString(), node);
                
            }
           
        }
    } 
#endregion

调用:

    protected DataTable dt;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            //NodeBind();
            TreeNode tn = new TreeNode();
            tn.Text = "西亚斯国际学院";
            addNode("1", tn);
            this.TreeView1.Nodes.Add(tn);
        }

    }

你可能感兴趣的:(c#)