dashCommerce 研究所得(1)

有一个Usercontrol,ProductCategories中有一个精典的DataSet递归程序:

 1 int catLevel = 0;
 2    private void BuildCategoryList(DataSet ds)
 3    {
 4
 5        ds.Relations.Add("NodeRelation", ds.Tables[0].Columns["categoryID"],ds.Tables[0].Columns["parentID"], false);
 6
 7        foreach (DataRow dbRow in ds.Tables[0].Rows)
 8        {
 9            if (int.Parse(dbRow["parentID"].ToString()) == 0)
10            {
11                catLevel = 0;
12                ddlCats.Items.Add(new ListItem(dbRow["categoryName"].ToString(), dbRow["categoryID"].ToString()));
13                PopulateSubTree(dbRow);
14            }

15        }

16
17    }

18    private void PopulateSubTree(DataRow dbRow)
19    {
20        catLevel++;
21        foreach (DataRow childRow in dbRow.GetChildRows("NodeRelation"))
22        {
23            ddlCats.Items.Add(new ListItem("---" + childRow["categoryName"].ToString(), childRow["categoryID"].ToString()));
24            PopulateSubTree(childRow);
25        }

26    }

27    public void LoadCategories(int productID)
28    {
29        lblID.Text = productID.ToString();
30        DataSet ds = CategoryController.GetDataSetList(); ;
31        BuildCategoryList(ds);
32        LoadCatList();
33
34    }

posted on 2008-04-30 10:46  newr2006  阅读(768)  评论(1)    收藏  举报

导航