Beispiel #1
0
 protected void InitiateRegion()
 {
     RegionList.DataSourceID   = "RegionDataSource";
     RegionList.DataTextField  = "regionname";
     RegionList.DataValueField = "regionid";
     RegionList.DataBind();
     RegionList.Items.Insert(0, "-Select Region-");
 }
        /// <summary>
        /// Binds the regions list.
        /// </summary>
        /// <param name="shippingRow">The shipping row.</param>
        private void BindRegionsList(ShippingMethodDto.ShippingMethodRow shippingRow)
        {
            List <CountryDto.StateProvinceRow> leftRegions  = new List <CountryDto.StateProvinceRow>();
            List <CountryDto.StateProvinceRow> rightRegions = new List <CountryDto.StateProvinceRow>();

            CountryDto dto = CountryManager.GetCountries(true);

            bool allToLeft = false;             // if true, then add all regions to the left list

            if (shippingRow != null)
            {
                ShippingMethodDto.ShippingRegionRow[] restrictedRegionRows = shippingRow.GetShippingRegionRows();
                if (restrictedRegionRows != null && restrictedRegionRows.Length > 0)
                {
                    foreach (CountryDto.StateProvinceRow stateProvinceRow in dto.StateProvince)
                    {
                        bool found = false;
                        foreach (ShippingMethodDto.ShippingRegionRow restrictedRegionRow in restrictedRegionRows)
                        {
                            if (stateProvinceRow.StateProvinceId == restrictedRegionRow.StateProvinceId)
                            {
                                found = true;
                                break;
                            }
                        }

                        if (found)
                        {
                            rightRegions.Add(stateProvinceRow);
                        }
                        else
                        {
                            leftRegions.Add(stateProvinceRow);
                        }
                    }

                    RegionList.LeftDataSource  = leftRegions;
                    RegionList.RightDataSource = rightRegions;
                }
                else
                {
                    // add all regions to the left list
                    allToLeft = true;
                }
            }
            else
            {
                allToLeft = true;
            }

            if (allToLeft)
            {
                // add all regions to the left list
                RegionList.LeftDataSource = dto.StateProvince;
            }

            RegionList.DataBind();
        }
 protected void BindRegionList()
 {
     try
     {
         RegionController sysmgr = new RegionController();
         List <Region>    info   = sysmgr.Region_List();
         info.Sort((x, y) => x.RegionDescription.CompareTo(y.RegionDescription));
         RegionList.DataSource     = info;
         RegionList.DataTextField  = nameof(Region.RegionDescription);
         RegionList.DataValueField = nameof(Region.RegionID);
         RegionList.DataBind();
         RegionList.Items.Insert(0, "select...");
     }
     catch (Exception ex)
     {
         errormsgs.Add(GetInnerException(ex).ToString());
         LoadMessageDisplay(errormsgs, "alert alert-danger");
     }
 }