Ejemplo n.º 1
0
 private static void FillDropDownList(WebControl ddlRegions, Dictionary <int, string> regions, int?selectedId)
 {
     foreach (int current in regions.Keys)
     {
         WebControl webControl = RegionSelector.CreateOption(current.ToString(CultureInfo.InvariantCulture), regions[current]);
         if (selectedId.HasValue && current == selectedId.Value)
         {
             webControl.Attributes.Add("selected", "true");
         }
         ddlRegions.Controls.Add(webControl);
     }
 }
Ejemplo n.º 2
0
        protected override void CreateChildControls()
        {
            this.Controls.Clear();
            if (!this.dataLoaded)
            {
                if (!string.IsNullOrEmpty(this.Context.Request.Form["regionSelectorValue"]))
                {
                    this.currentRegionId = new int?(int.Parse(this.Context.Request.Form["regionSelectorValue"]));
                }
                this.dataLoaded = true;
            }
            if (this.currentRegionId.HasValue)
            {
                XmlNode region = RegionHelper.GetRegion(this.currentRegionId.Value);
                if (region != null)
                {
                    if (region.Name == "county")
                    {
                        this.countyId   = new int?(this.currentRegionId.Value);
                        this.cityId     = new int?(int.Parse(region.ParentNode.Attributes["id"].Value));
                        this.provinceId = new int?(int.Parse(region.ParentNode.ParentNode.Attributes["id"].Value));
                    }
                    else
                    {
                        if (region.Name == "city")
                        {
                            this.cityId     = new int?(this.currentRegionId.Value);
                            this.provinceId = new int?(int.Parse(region.ParentNode.Attributes["id"].Value));
                        }
                        else
                        {
                            if (region.Name == "province")
                            {
                                this.provinceId = new int?(this.currentRegionId.Value);
                            }
                        }
                    }
                }
            }
            this.Controls.Add(RegionSelector.CreateTitleControl(this.ProvinceTitle));
            this.ddlProvinces = this.CreateDropDownList("ddlRegions1");
            RegionSelector.FillDropDownList(this.ddlProvinces, RegionHelper.GetAllProvinces(), this.provinceId);
            this.Controls.Add(RegionSelector.CreateTag("<span>"));
            this.Controls.Add(this.ddlProvinces);
            this.Controls.Add(RegionSelector.CreateTag("</span>"));
            this.Controls.Add(RegionSelector.CreateTitleControl(this.CityTitle));
            this.ddlCitys = this.CreateDropDownList("ddlRegions2");
            if (this.provinceId.HasValue)
            {
                RegionSelector.FillDropDownList(this.ddlCitys, RegionHelper.GetCitys(this.provinceId.Value), this.cityId);
            }
            this.Controls.Add(RegionSelector.CreateTag("<span>"));
            this.Controls.Add(this.ddlCitys);
            this.Controls.Add(RegionSelector.CreateTag("</span>"));

            Dictionary <int, string> dtCountys = new Dictionary <int, string>();

            if (this.cityId.HasValue)
            {
                dtCountys = RegionHelper.GetCountys(this.cityId.Value);
            }

            Label countyTitle = RegionSelector.CreateTitleControl(this.CountyTitle);

            if (dtCountys.Count <= 0)
            {
                countyTitle.Style.Add("display", "none");
            }
            else
            {
                countyTitle.Style.Add("display", "block");
            }
            this.Controls.Add(countyTitle);
            this.ddlCountys = this.CreateDropDownList("ddlRegions3");
            if (this.cityId.HasValue)
            {
                RegionSelector.FillDropDownList(this.ddlCountys, dtCountys, this.countyId);
            }

            if (dtCountys.Count <= 0)
            {
                this.ddlCountys.Style.Add("display", "none");
            }
            else
            {
                this.ddlCountys.Style.Add("display", "block");
            }
            this.Controls.Add(RegionSelector.CreateTag("<span>"));
            this.Controls.Add(this.ddlCountys);
            this.Controls.Add(RegionSelector.CreateTag("</span>"));
        }