你的位置:首页 > ASP.net教程

[ASP.net教程]关于asp.net的一点小问题有谁帮忙解答一下?


 public IList<Category> Categories { get; set; }
        protected void Page_Load(object sender, EventArgs e)
        {

//这是静态给categories赋值,怎么动态赋值呢,就是连接数据库后查询数据绑定categories,使他的数据成下面一样显示
            Categories = new List<Category>
            {
                new Category
                {
                    Name = "category 1",
                    Children = new List<Category>
                    {
                        new Category
                        {
                            Name="category 1-1",
                            Children = new List<Category>{}
                        },
                        new Category
                        {
                            Name="category 1-2",
                            Children = new List<Category>{}
                        },
                    }
                },
                new Category{
                    Name ="category 2",
                    Children = new List<Category>{
                        new Category{
                            Name = "category 2-1",
                            Children = new List<Category>{}
                        },
                        new Category
                        {
                            Name = "category 2-2",
                            Children = new List<Category>{}
                        }
                    }
                }
            };
        }