Ejemplo n.º 1
0
        private void PopulateNodes(TreeNodeCollection nodes, int ParentID)
        {
            DataTable dt = bll.GetList(ParentID);

            for (int i = 0; i < dt.Rows.Count; i++)
            {
                TreeNode tn = new TreeNode();
                tn.Text         = dt.Rows[i]["categoryname"].ToString();
                tn.Value        = dt.Rows[i]["categoryid"].ToString();
                tn.ImageToolTip = dt.Rows[i]["categoryname"].ToString();
                tn.ToolTip      = dt.Rows[i]["categoryname"].ToString();
                tn.SelectAction = TreeNodeSelectAction.Select;
                nodes.Add(tn);

                PopulateNodes(tn.ChildNodes, Convert.ToInt32(dt.Rows[i]["categoryid"]));
            }
        }
        private void BindCategory(int ParentID, int Level, string CategoryPath)
        {
            ListBox box = null;

            switch (Level)
            {
            case 1:
                box = ListBox1;
                break;

            case 2:
                box = ListBox2;
                break;

            case 3:
                box = ListBox3;
                break;

            default:
                break;
            }

            if (box != null)
            {
                DataTable dt = bll.GetList(ParentID);
                if (dt.Rows.Count > 0)
                {
                    box.DataSource     = dt;
                    box.DataTextField  = "categoryname";
                    box.DataValueField = "categoryid";
                    box.DataBind();
                    box.Visible = true;
                    if (CategoryPath == null)
                    {
                        box.Items[0].Selected = true;
                    }
                    else
                    {
                        box.SelectedValue = CategoryPath.Split('/')[Level - 1];
                    }
                    SelectedCategoryID = Convert.ToInt32(box.SelectedValue);
                    BindCategory(Convert.ToInt32(box.SelectedValue), Level + 1, CategoryPath);
                }
                else
                {
                    switch (Level)
                    {
                    case 1:
                        ListBox1.Visible = false;
                        ListBox2.Visible = false;
                        ListBox3.Visible = false;
                        break;

                    case 2:
                        ListBox2.Visible = false;
                        ListBox3.Visible = false;
                        break;

                    case 3:
                        ListBox3.Visible = false;
                        break;

                    default:
                        break;
                    }
                }
            }
        }