" DataView dv = new DataView(ds.Tables[0]);"
最好这样写,应该写成:
  DataView dv= ds.Table[0].DefalutView;

解决方案 »

  1.   

    dataset和dataview不要放在viewstate里,这样viewstate会过大可以放在Session里,这样放在服务器端较好(虽然也占服务器资源)另外,你id全设置成0001做什么?
      

  2.   

    TO:Simplare(简单) 
    ID设置只是发贴的时候说说而已..程序本身是接受变量的。是不同的。....我现在想怎么才能实现我要的功能.有没有别的好方法.放在Session里面该怎么样写
      

  3.   

    ft,写错了!
    ds.Table[0].DefalutView;应该是.DefaultView
      

  4.   

    你可以把DataView dv 声明成全局static变量
    然后就可以在此访问它了。
    也不用什么session了
      

  5.   

    private void CreateDataSet()
    {
    DataSet ds=(DataSet) this.ViewState["ds"]; 
    DataView dvTree = ds.Tables[0].DefaultView ;
    //过滤ParentID,得到当前的所有子节点
    //dvTree.RowFilter =  "[SendPID] = " + ParentID;
    dvTree.AllowEdit=true;
    foreach(DataRowView Row in dvTree) 
    {
    string content = "";
    content = Row["idx"].ToString() 
    Row["txtcontent"] = content;
    Row.EndEdit();
    }
    this.ViewState["dv"]=dvTree;
                    }private void AddTree(string ParentID,TreeNode pNode)
    {
    //DataSet ds=(DataSet) this.ViewState["ds"]; 
    //DataView dvTree = new DataView(ds.Tables[0]);
    //过滤ParentID,得到当前的所有子节点
    DataView dvTree=(DataView)this.ViewState["dv"];
    dvTree.RowFilter =  "[SendPID] = " + ParentID;
                
    foreach(DataRowView Row in dvTree) 
    {
    TreeNode Node=new TreeNode() ;
    if(pNode == null) 
    {    //添加根节点
    Node.Text = Row["txtcontent"].ToString();
    j_TreeView.Nodes.Add(Node);
    Node.Expanded=true;
    AddTree(Row["acceptpid"].ToString(), Node);    //再次递归

    else 
    {   //?添加当前节点的子节点
    Node.Text = Row["txtcontent"].ToString();
    pNode.Nodes.Add(Node);
    Node.Expanded = true;
    AddTree(Row["acceptpid"].ToString(),Node);     //再次递归
    }
    }    
    }
    这就是大概的程序...请各位看看那里有问题.现在总报1行不存在.
      

  6.   

    把ds放在Session中,
    我以前也遇到过类似问题.
      

  7.   

    在位置 1 处没有任何行。 
    说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 异常详细信息: System.IndexOutOfRangeException: 在位置 1 处没有任何行。源错误: 
    行 166: else 
    行 167: {   //?添加当前节点的子节点
    行 168: Node.Text = Row["txtcontent"].ToString();
    行 169: pNode.Nodes.Add(Node);
    行 170: Node.Expanded = true;
     源文件: c:\inetpub\wwwroot\police\j_track_show.aspx.cs    行: 168 堆栈跟踪: 
    [IndexOutOfRangeException: 在位置 1 处没有任何行。]
       System.Data.DataView.GetRecord(Int32 recordIndex)
       System.Data.DataView.IsOriginalVersion(Int32 index)
       System.Data.DataRowView.get_Item(String property)
       police.j_show_track.AddTree(String ParentID, TreeNode pNode) in c:\inetpub\wwwroot\police\j_track_show.aspx.cs:168
       police.j_show_track.AddTree(String ParentID, TreeNode pNode) in c:\inetpub\wwwroot\police\j_track_show.aspx.cs:164
       police.j_show_track.Page_Load(Object sender, EventArgs e) in c:\inetpub\wwwroot\police\j_track_show.aspx.cs:41
       System.Web.UI.Control.OnLoad(EventArgs e)
       System.Web.UI.Control.LoadRecursive()
       System.Web.UI.Page.ProcessRequestMain()
      

  8.   

    停在 Node.Text = Row["txtcontent"].ToString();
      

  9.   

    这说明Row[]中没有txtcontent的索引
    需要调试一下
    在出现错误的一行添加断点
    然后添加Row的监视,看看Row里面是否有值,然后查看每个值相对索引是什么
      

  10.   

    我发现在了问题所在了...当执行再次递归的时候dvTree.RowFilter =  "[SendPID] = " + ParentID; 如果没有数据,执行后dvTree.count=0 这样的话foreach循环以后并不是再执行一次dvTree.RowFilter =  "[SendPID] = " + ParentID 程序只在foreach里面执行.dvtree里面还是没有数据...这个问题该怎么解决呢