给treeview递归增加菜单

    private void BindDataToTree(TreeNodeCollection tns, string id, DataTable dt)
    {

        DataView dv = dt.DefaultView;
        dv.RowFilter = "upNo=" + id;
        TreeNode tn;
        string strID;
        foreach (DataRowView dr in dv)
        {
            strID = dr["no"].ToString();
            if (strID != "")
            {
                tn = new TreeNode();
                tn.Value = dr["no"].ToString();
                tn.Text = dr["Name"].ToString();
                tn.ImageUrl = "../images/Folder.gif";
                tns.Add(tn);
                BindDataToTree(tns[tns.Count - 1].ChildNodes, strID, dt);
            }
        }
    }

你可能感兴趣的:(treeview)