private void intiTree(ref TreeNodeCollection Nds,int parentId)
去掉ref               ^^^   strId=drv["node_id"];改成intId = drv["node_id"];

解决方案 »

  1.   

    intiTree(Nds(Nds.Count - 1).Nodes,intId);改成intiTree(tmpNd.Nodes,intId);

    intiTree(Nds[Nds.Count - 1].Nodes, intId);
    还有
    你还是把函数intiTree写成InitTree吧
      

  2.   

    这一句intiTree(TreeView1.Nodes,0);提示错误:
    c:\inetpub\wwwroot\Importent\TreeView\default.aspx.cs(30): 与“Importent.TreeView._default.intiTree(System.Windows.Forms.TreeNodeCollection, int)”最匹配的重载方法具有一些无效参数
    c:\inetpub\wwwroot\Importent\TreeView\default.aspx.cs(30): 参数“1” : 无法从“Microsoft.Web.UI.WebControls.TreeNodeCollection”转换为“System.Windows.Forms.TreeNodeCollection”这一句foreach(DataRowView drv in dv)也有问题
      

  3.   

    tmpNd.ID=strId;
    tmpNd.ImageUrl=drv["icon"].ToString();
    提示:
    c:\inetpub\wwwroot\Importent\TreeView\default.aspx.cs(84): “System.Windows.Forms.TreeNode”并不包含对“ID”的定义
    c:\inetpub\wwwroot\Importent\TreeView\default.aspx.cs(86): “System.Windows.Forms.TreeNode”并不包含对“ImageUrl”的定义
      

  4.   

    关键在这个地方有问题:
    Private Sub intiTree(ByRef Nds As TreeNodeCollection, ByVal parentId As Integer) 
    Dim dv As New DataView() 
    Dim drv As DataRowView 
    Dim tmpNd As TreeNode 
    Dim intId As Integer 
    dv.Table = ds.Tables("tree") 
    dv.RowFilter = "PARENTID=’" & parentId & "’" 
    For Each drv In dv 
    tmpNd = New TreeNode() 
    strId = drv("NODE_ID") 
    tmpNd.ID = strId 
    tmpNd.Text = drv("NODE_NAME ") 
    tmpNd.ImageUrl = drv("ICON").ToString 
    Nds.Add(tmpNd) 
    intiTree(Nds(Nds.Count - 1).Nodes, intId) 
    Next 
    End Sub
      

  5.   

    找不着命名空间把using System.Windows.Forms; 去掉添加Microsoft.Web.UI.WebControls.dllusing Microsoft.Web.UI.WebControls;TreeNode是指Microsoft.Web.UI.WebControls.TreeNode
      

  6.   

    private void intiTree(TreeNodeCollection Nds,int parentId)
    foreach(drv in dv)
    提示:
    c:\inetpub\wwwroot\Importent\TreeView\default.aspx.cs(68): 找不到类型或命名空间名称“TreeNodeCollection”(是否缺少 using 指令或程序集引用?)
    c:\inetpub\wwwroot\Importent\TreeView\default.aspx.cs(79): 在 foreach 语句中,类型和标识符都是必需的
      

  7.   

    using System;
    using System.Collections;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Web;
    using System.Web.SessionState;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.HtmlControls;using System.Data.SqlClient;
    using System.Configuration;
    namespace Importent.TreeView
    {
    /// <summary>
    /// _default 的摘要说明。
    /// </summary>
    public class _default : System.Web.UI.Page
    {
    protected Microsoft.Web.UI.WebControls.TreeView TreeView1;

    private void Page_Load(object sender, System.EventArgs e)
    {
    // 在此处放置用户代码以初始化页面
    CreateDataSet();
    intiTree(TreeView1.Nodes,0); }
    #region Web 窗体设计器生成的代码
    override protected void OnInit(EventArgs e)
    {
    //
    // CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
    //
    InitializeComponent();
    base.OnInit(e);
    }

    /// <summary>
    /// 设计器支持所需的方法 - 不要使用代码编辑器修改
    /// 此方法的内容。
    /// </summary>
    private void InitializeComponent()
    {    
    //this.Load += new System.EventHandler(this.Page_Load);
    base.Load += new System.EventHandler(this.Page_Load); }
    #endregion //建立数据集 root
    public void CreateDataSet()
    {
    string connString=ConfigurationSettings.AppSettings["Study"];
    SqlConnection conn=new SqlConnection(connString);
    string sql="select nodeid,nodename,parentid,address,icon from tree_info"; SqlDataAdapter da=new SqlDataAdapter(sql,conn);
    DataSet ds=new DataSet(); da.Fill(ds,"tree_info");
    } //Children nodes
    private void intiTree(TreeNodeCollection Nds,int parentId)
    {
    DataView dv= new DataView();
    DataRowView drv;
    TreeNode tmpNd;
    int intId; DataSet ds=new DataSet();
    dv.Table=ds.Tables["tree_info"];
    dv.RowFilter = "PARENTID="+ parentId +""; foreach(drv in dv)
    {
    tmpNd=new TreeNode();
    intId=int.Parse(drv["node_id"].ToString());
    tmpNd.ID=strId;
    tmpNd.Text=drv["node_name"].ToString();
    tmpNd.ImageUrl=drv["icon"].ToString();
    Nds.Add(tmpNd);
    intiTree(tmpNd.Nodes ,intId);//or intiTree(Nds[Nds.Count-1].Nodes,intId);
    }
    }
    }
    }
      

  8.   

    上面那段代码是我更改过的,可是private void intiTree(TreeNodeCollection Nds,int parentId)中的TreeNodeCollection是不是指
    using System.Windows.Forms;
      

  9.   

    using System.Windows.Forms;这句删掉
      

  10.   

    using System.Windows.Forms;这行删掉
      

  11.   

    你的是web下的,TreeNode这样的定义是在winform下的,应该这样定义:Microsoft.Web.UI.WebControls.TreeNodeCollection Nds
      

  12.   

    这样定以后又出现了好多错误!
    我觉得都是定义类型不对!例如
    TreeNode tmpNd;中的tmpNode
    foreach(DataRow drv in dv)中的drv我真是郁闷透了!给我个方法吧!