目的是要显示全路径;但点击分类节点报错。敬候高人指点迷津。感谢先!!! http://ftpbbs.bccn.net/003/month_1111/20111111_a7d514f011ba754f3cfanTMqTf27HDa0.jpg.thumb.jpg
    /// <summary>
    /// 目的:将数据库news_class表的path字段的值分拆开,最后返回组合的classname值,例:根目录/一级分类/二级分类/三件分类;
       /// </summary>
    /// <param name="tpath"></param>
    /// <returns></returns>
 public String getpath(string tpath)
    {
        string[] pathlist;
        TreeNode tn = new TreeNode();
        string Path = null;
        //string patht = null;        if (tpath.Substring(0, 2) == "0/")
        {            tpath = "1";        }        pathlist = tpath.Split(new Char[] { '/' }, StringSplitOptions.RemoveEmptyEntries);         foreach (string path in pathlist)
        {            tn = TreeView1.FindNode(path);
            patht = tn.Text;   在这里报错!
            Path += "/"+patht;
        }
        return "根目录" +Path ;
       
    }

解决方案 »

  1.   

    源代码:http://bbs.bccn.net/attachment.php?aid=60360&k=e69d05058bc0a3438ed0b5b1332ddc2d&t=1320982422老在树节点点击后报错,图示:
      

  2.   

    以下是浏览器报错的代码:
    ======================================
    Server Error in '/class' Application.
    --------------------------------------------------------------------------------Object reference not set to an instance of an object. 
    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.Source Error: 
    Line 139:
    Line 140:            tn = TreeView1.FindNode(path);
    Line 141:            patht = tn.Text;
    Line 142:            Path += "/"+patht;
    Line 143:        }
     Source File: e:\gkh\新闻系统管理\class\admin\new_class.aspx.cs    Line: 141 Stack Trace: 
    [NullReferenceException: Object reference not set to an instance of an object.]
       admin_class.getpath(String tpath) in e:\gkh\新闻系统管理\class\admin\new_class.aspx.cs:141
       admin_class.Page_Load(Object sender, EventArgs e) in e:\gkh\新闻系统管理\class\admin\new_class.aspx.cs:32
       System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +13
       System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +45
       System.Web.UI.Control.OnLoad(EventArgs e) +80
       System.Web.UI.Control.LoadRecursive() +49
       System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3743============================================================
    高手救命呀!!! 
      

  3.   

    tn = TreeView1.FindNode(path);
    没有找到这个path的节点吧,跟踪一下呢
      

  4.   

    这是跟踪结果:
    =============================================================
    Server Error in '/class' Application.
    --------------------------------------------------------------------------------Object reference not set to an instance of an object. 
    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.Source Error: 
    Line 147:
    Line 148:            tn = TreeView1.FindNode(path);
    Line 149:            Trace.Warn(tn.Text);
    Line 150:
    Line 151:            Path += "/" + tn.Text;
     Source File: e:\gkh\新闻系统管理\class\admin\new_class.aspx.cs    Line: 149 Stack Trace: 
    [NullReferenceException: Object reference not set to an instance of an object.]
       admin_class.getpath(String tpath) in e:\gkh\新闻系统管理\class\admin\new_class.aspx.cs:149
       admin_class.Page_Load(Object sender, EventArgs e) in e:\gkh\新闻系统管理\class\admin\new_class.aspx.cs:33
       System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +13
       System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +45
       System.Web.UI.Control.OnLoad(EventArgs e) +80
       System.Web.UI.Control.LoadRecursive() +49
       System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3728 
    --------------------------------------------------------------------------------
    Version Information: Microsoft .NET Framework Version:2.0.50727.42; ASP.NET Version:2.0.50727.42 
    Request Details 
    Session Id: q24la2jj5h0gomrkx5sghx30 Request Type: GET 
    Time of Request: 2011/11/11 下午 03:55:18 Status Code: 500 
    Request Encoding: Unicode (UTF-8) Response Encoding: Unicode (UTF-8) 
    Trace Information 
    Category Message From First(s) From Last(s) 
    aspx.page Begin PreInit   
    aspx.page End PreInit 1.26554012142629E-05 0.000013 
    aspx.page Begin Init 2.52446382586793E-05 0.000013 
    aspx.page End Init 4.21555985789741E-05 0.000017 
    aspx.page Begin InitComplete 5.09855077912069E-05 0.000009 
    aspx.page End InitComplete 5.97402304467961E-05 0.000009 
    aspx.page Begin PreLoad 6.79084979605647E-05 0.000008 
    aspx.page End PreLoad 8.23322869870867E-05 0.000014 
    aspx.page Begin Load 9.14599349636285E-05 0.000009 
     一级分类 0.0123688081051108 0.012277 Unhandled Execution Error 
    Object reference not set to an instance of an object.
      at admin_class.getpath(String tpath) in e:\gkh\新闻系统管理\class\admin\new_class.aspx.cs:line 149
      at admin_class.Page_Load(Object sender, EventArgs e) in e:\gkh\新闻系统管理\class\admin\new_class.aspx.cs:line 33
      at System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e)
      at System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e)
      at System.Web.UI.Control.OnLoad(EventArgs e)
      at System.Web.UI.Control.LoadRecursive()
      at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) 
    =============================================================
    红色的部分就是跟踪到的结果,只能找到第一分割的字符,以后的都找不到,所以报错。但我明明传过来了
    我还把代码改成这样试了试,所有结果都传过来了呀!
      public String getpath(string tpath)
        {
            string[] pathlist;
            TreeNode tn = new TreeNode();
            string Path = null;
            pathlist = tpath.Split(new Char[] { '/' },StringSplitOptions.RemoveEmptyEntries);        foreach (string path in pathlist)
            {            //tn = TreeView1.FindNode(path);
                //Trace.Warn(tn.Text);
                Path +=path;
                //Path += "/" + tn.Text;
            }
                   return "根目录" +Path ;
           
        }高手救救我呀!!!!!!!!!!
      

  5.   

    高手哥看看我这张树节点图,问题是不是这句:TreeView1.FindNode(path);它只能一级节点,一级以下的都不适用。
    这是图:
    这是源码,库文件都有。http://bbs.bccn.net/attachment.php?aid=60360&k=c6b12611098a80b7955c092933426ff7&t=1320999937救命呀!
      

  6.   

    value =2的 treenode 没有找到啊。