代码改变世界

TreeView

2016-06-15 11:31  FingalZhu  阅读(169)  评论(0编辑  收藏  举报

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BindTreeViewList();
            }
        }
        private void BindTreeViewList()
        {
            Provinces m_provinces = new Provinces();
            IList<Provinces> il_provinces= ProvincesByManager.SelectCollection("1=1",false,false);
            TreeNode node;
            for (int i = 0; i<il_provinces.Count; i++)
            {
                node = new TreeNode();
                node.Text = il_provinces[i].Province;
                node.Value = il_provinces[i].Provinceid;
                this.TreeView_areaList.Nodes.Add(node);
            }
        }
        protected void TreeView_areaList_SelectedNodeChanged(object sender, EventArgs e)
        {
            TreeView_areaList.SelectedNode.ChildNodes.Clear();
            IList<Cities> il_cities = CitiesByManager.SelectCollection("1=1 and provinceid=" + TreeView_areaList.SelectedValue + "", false, false);
            TreeNode node;
            if (il_cities.Count > 0)
            {
                for (int i = 0; i < il_cities.Count; i++)
                {
                    node = new TreeNode();
                    node.Text = il_cities[i].City;
                    node.Value = il_cities[i].Cityid;
                    TreeView_areaList.SelectedNode.ChildNodes.Add(node);
                    TreeView_areaList.SelectedNode.Expand();
                }
            }
            else {
                IList<Areas> il_areas = AreasByManager.SelectCollection("1=1 and cityid=" + TreeView_areaList.SelectedValue + "", false, false);
                if (il_areas.Count > 0)
                {
                    for (int i = 0; i < il_areas.Count; i++)
                    {
                        node = new TreeNode();
                        node.Text = il_areas[i].Area + "<input id=\"txt_area" + i + "\" type=\"text\" runat=\"server\" value=\"" + il_areas[i].Area + "\" /><input id=\"btn_\" type=\"button\" runat=\"server\" value=\"修改\" />";
                        node.Value = il_areas[i].Areaid;
                        TreeView_areaList.SelectedNode.ChildNodes.Add(node);
                        TreeView_areaList.SelectedNode.Expand();
                    }
                }
            }
        }