要做一个项目列表,可以无限级开下去
现在的数据结构是这样的
id(自增) name(名称) followid(项目ID根为0,子项目的ID为父记录的ID号)例:
1) 项目一 0
2) 项目二 1
3) 项目三 0
4) 项目四 3
5) 项目五 4
这个递归怎么写,各位给指点一下吧

解决方案 »

  1.   

    首先把根节点加上去,然后:循环每一个根节点
    public void addTreeNode()
    {
    如果是子节点,加入到根节点下面
    addTreeNode()
    }
      

  2.   

    public void GetDeptIDList(NameValueCollection nvCondition)
    {
    bool bReturn = false;
    string strTmp = "";
    DataTable dtData = new DataTable();
    cDepartment cDept = new cDepartment();
    bool bl = cDept.Query(nvCondition,out dtData);
    if(!bl) return;
    if(dtData != null && dtData.Rows.Count>0)
    {
    foreach(DataRow dr in dtData.Rows)
    {
    strTmp += dr["ID"].ToString()+",";
    this.deptIDList += dr["ID"].ToString()+",";
    }
    strTmp = strTmp.Substring(0,strTmp.Length-1);
    bReturn = true;
    }
    if(bReturn)
    {
    nvCondition.Clear();
    nvCondition.Add("UpperID",strTmp);
    GetDeptIDList(nvCondition);
    }
    else 
    {
    if(this.deptIDList.Length>0)
    this.deptIDList = deptIDList.Substring(0,deptIDList.Length-1);
    }
    }