递规得出某分类下面的所有子类ID群字段:ID    Pid    Name
1      0     新闻
2      1    国际新闻
3      1    国内新闻
4      3    江苏新闻如何用递归,得到新闻下面的所有子类的ID群,如:2,3,4给个class类吧,谢谢

解决方案 »

  1.   


    DataView dvTree = new DataView(ds.Tables[0]);  //数据表的视图
    ArrayList children =  new  ArrayList();        //用于保存子节点的ID    public void AddChildren(int ID)
        {      
            dvTree.RowFilter = "[PID] = " + ID;
           foreach (DataRowView Row in dvTree)
           {
                children.Add( Convert.ToInt32(Row["ID"]) ); 
                AddChildren( Convert.ToInt32(Row["ID"]) );        //递归
            }
        }