数据库结构
表名:Product_Class
Product_Class_id           Name            Parent            Depth
    1                       aa               0                1
    2                       bb               0                1
    3                       aa1              1                2
    4                       aa2              1                2
    5                       bb1              2                2
    6                       bb2              2                2
 表名:Product_List
Product_List_ID             Product_Class_ID           Name
    1                         3                        aa1product
    2                         4                        aa2product
    3                         5                        bb1product
    4                         6                        bb2product
      
我想用treeview控件实现如下的功能,一开始列出depth=1的所有类别名字
点一下+号列出下一级的类别,依次类推,直到点到最后一层。在最后一层中列出属于这个类别下的产品名字,并且每一个产品名字前面有一个复选框如过选中的话它的value就为它的ID值?      

解决方案 »

  1.   

    http://www.microsoft.com/china/community/Column/30.mspx递归就可以了。
      

  2.   

    http://goody9807.cnblogs.com/archive/2005/07/01/184754.html
      

  3.   

    http://www.cnblogs.com/renyu732/archive/2005/06/28/182553.html
      

  4.   

    我的程序如下,要商品显示应该怎么修改啊??
    private void Page_Load(object sender, System.EventArgs e)
    {
    string SelectMember_Name="select * from Product_Class,Product_List where isvalid=0";
    SqlConnection myConnection = new SqlConnection(ConfigurationSettings.AppSettings["ConnectionString"]);
    myConnection.Open();
    SqlCommand cmd1 = new SqlCommand(SelectMember_Name,myConnection);
    SqlDataAdapter adp = new SqlDataAdapter(SelectMember_Name,myConnection);
    DataSet ds=new DataSet();
    adp.Fill(ds);
    this.ViewState["ds"]=ds; 
    AddTree(0, (TreeNode)null); }
    public void AddTree(int Parent,TreeNode pNode) 
    { DataSet ds=(DataSet) this.ViewState["ds"]; 
    DataView dvTree = new DataView(ds.Tables[0]);
    //过滤ParentID,得到当前的所有子节点
    dvTree.RowFilter =  "[Parent] = " + Parent;
    foreach(DataRowView Row in dvTree) 
    { TreeNode Node=new TreeNode() ;
    if(pNode == null) 
    {    //添加根节点
    Node.Text = Row["Name"].ToString();
    TreeView1.Nodes.Add(Node);
    Node.Expanded=true;
    AddTree(Int32.Parse(Row["Product_Class_ID"].ToString()), Node);    //再次递归

    else 
    {  //添加当前节点的子节点 Node.Text = Row["Name"].ToString();
    pNode.Nodes.Add(Node);
    Node.Expanded = false;
    AddTree(Int32.Parse(Row["Product_Class_ID"].ToString()),Node);     //再次递归 } }      
    }
      

  5.   

    点击时用Sql语句差下一级节点就可以,没什么呀
      

  6.   

    to: csdnzm(明飞) ( 
    那我在程序里面应该怎么改啊??
      

  7.   

    我写错了后面的 where isvalid=0是没有的!!
      

  8.   

    帮你搞定了!private void Page_Load(object sender, System.EventArgs e)
    {
    //把2个表建立关联
    string SelectMember_Name="SELECT dbo.Product_Class.*, dbo.Product_List.Name AS Pname FROM dbo.Product_Class LEFT OUTER JOIN dbo.Product_List ON dbo.Product_Class.Product_Class_id = dbo.Product_List.Product_Class_ID";
    SqlConnection myConnection = new SqlConnection(System.Configuration.ConfigurationSettings.AppSettings["ConnectionString2"]);
    myConnection.Open();
    SqlCommand cmd1 = new SqlCommand(SelectMember_Name,myConnection);
    SqlDataAdapter adp = new SqlDataAdapter(SelectMember_Name,myConnection);
    DataSet ds=new DataSet();
    adp.Fill(ds);
    this.ViewState["ds"]=ds; 
    AddTree(0, (TreeNode)null); }
    public void AddTree(int Parent,TreeNode pNode) 
    { DataSet ds=(DataSet) this.ViewState["ds"]; 
    DataView dvTree = new DataView(ds.Tables[0]);
    //过滤ParentID,得到当前的所有子节点
    dvTree.RowFilter =  "[Parent] = " + Parent;
    if (dvTree.Count ==0) //为最后一层节点
    {
    DataView dv = new DataView(ds.Tables[0]);
        dv.RowFilter="[Product_Class_id]= "+Parent;
    foreach(DataRowView Row in dv) 
    {
      TreeNode Node=new TreeNode() ;
    Node.Text = Row["Pname"].ToString();
    pNode.Nodes.Add(Node);
    }
    return;
     }
    foreach(DataRowView Row in dvTree) 
    { TreeNode Node=new TreeNode() ;
    if(pNode == null) 
    {    //添加根节点
    Node.Text = Row["Name"].ToString();
    TreeView1.Nodes.Add(Node);
    Node.Expanded=true;
    AddTree(Int32.Parse(Row["Product_Class_ID"].ToString()), Node);    //再次递归

    else 
    {  //添加当前节点的子节点 Node.Text = Row["Name"].ToString();
    pNode.Nodes.Add(Node);
    Node.Expanded = false;
    AddTree(Int32.Parse(Row["Product_Class_ID"].ToString()),Node);     //再次递归 } }      
    }如果看不清 我写在blog上
      

  9.   

    http://www.cnblogs.com/goody9807/archive/2005/07/06/187209.html