/// <summary>
        /// Binds the countries list.
        /// </summary>
        /// <param name="shippingRow">The shipping row.</param>
        private void BindCountriesList(ShippingMethodDto.ShippingMethodRow shippingRow)
        {
            List <CountryDto.CountryRow> leftCountries  = new List <CountryDto.CountryRow>();
            List <CountryDto.CountryRow> rightCountries = new List <CountryDto.CountryRow>();

            CountryDto dto = CountryManager.GetCountries(true);

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

            if (shippingRow != null)
            {
                ShippingMethodDto.ShippingCountryRow[] restrictedCountryRows = shippingRow.GetShippingCountryRows();
                if (restrictedCountryRows != null && restrictedCountryRows.Length > 0)
                {
                    foreach (CountryDto.CountryRow countryRow in dto.Country)
                    {
                        bool found = false;
                        foreach (ShippingMethodDto.ShippingCountryRow restrictedCountryRow in restrictedCountryRows)
                        {
                            if (countryRow.CountryId == restrictedCountryRow.CountryId)
                            {
                                found = true;
                                break;
                            }
                        }

                        if (found)
                        {
                            rightCountries.Add(countryRow);
                        }
                        else
                        {
                            leftCountries.Add(countryRow);
                        }
                    }

                    CountryList.LeftDataSource  = leftCountries;
                    CountryList.RightDataSource = rightCountries;
                }
                else
                {
                    // add all countries to the left list
                    allToLeft = true;
                }
            }
            else
            {
                allToLeft = true;
            }

            if (allToLeft)
            {
                // add all countries to the left list
                CountryList.LeftDataSource = dto.Country;
            }

            CountryList.DataBind();
        }
        /// <summary>
        /// Saves the changes.
        /// </summary>
        /// <param name="context">The context.</param>
        public void SaveChanges(IDictionary context)
        {
            ShippingMethodDto dto = (ShippingMethodDto)context[_ShippingMethodDtoString];

            if (dto == null)
            {
                // dto must be created in base shipping control that holds tabs
                return;
            }

            ShippingMethodDto.ShippingMethodRow shippingRow = null;

            // create the row if it doesn't exist; or update its modified date if it exists
            if (dto.ShippingMethod.Count > 0)
            {
                shippingRow = dto.ShippingMethod[0];
            }
            else
            {
                return;
            }

            // 1. populate countries

            // a). delete rows from dto that are not selected
            foreach (ShippingMethodDto.ShippingCountryRow row in shippingRow.GetShippingCountryRows())
            {
                bool found = false;
                foreach (ListItem item in CountryList.RightItems)
                {
                    if (String.Compare(item.Value, row.CountryId.ToString(), true) == 0)
                    {
                        found = true;
                        break;
                    }
                }

                if (!found)
                {
                    row.Delete();
                }
            }

            // b). add selected rows to dto
            foreach (ListItem item in CountryList.RightItems)
            {
                bool exists = false;
                foreach (ShippingMethodDto.ShippingCountryRow row in shippingRow.GetShippingCountryRows())
                {
                    if (String.Compare(item.Value, row.CountryId.ToString(), true) == 0)
                    {
                        exists = true;
                        break;
                    }
                }

                if (!exists)
                {
                    ShippingMethodDto.ShippingCountryRow restrictedRow = dto.ShippingCountry.NewShippingCountryRow();
                    restrictedRow.CountryId        = Int32.Parse(item.Value);
                    restrictedRow.ShippingMethodId = shippingRow.ShippingMethodId;

                    // add the row to the dto
                    dto.ShippingCountry.Rows.Add(restrictedRow);
                }
            }


            // 2. populate regions

            // a). delete rows from dto that are not selected
            foreach (ShippingMethodDto.ShippingRegionRow row in shippingRow.GetShippingRegionRows())
            {
                bool found = false;
                foreach (ListItem item in RegionList.RightItems)
                {
                    if (String.Compare(item.Value, row.StateProvinceId.ToString(), true) == 0)
                    {
                        found = true;
                        break;
                    }
                }

                if (!found)
                {
                    row.Delete();
                }
            }

            // b). add selected rows to dto
            foreach (ListItem item in RegionList.RightItems)
            {
                bool exists = false;
                foreach (ShippingMethodDto.ShippingRegionRow row in shippingRow.GetShippingRegionRows())
                {
                    if (String.Compare(item.Value, row.StateProvinceId.ToString(), true) == 0)
                    {
                        exists = true;
                        break;
                    }
                }

                if (!exists)
                {
                    ShippingMethodDto.ShippingRegionRow restrictedRow = dto.ShippingRegion.NewShippingRegionRow();
                    restrictedRow.StateProvinceId  = Int32.Parse(item.Value);
                    restrictedRow.ShippingMethodId = shippingRow.ShippingMethodId;

                    // add the row to the dto
                    dto.ShippingRegion.Rows.Add(restrictedRow);
                }
            }

            // 3. populate payments restrictions

            // a). delete rows from dto that are not selected
            foreach (ShippingMethodDto.ShippingPaymentRestrictionRow row in shippingRow.GetShippingPaymentRestrictionRows())
            {
                bool found = false;
                foreach (ListItem item in PaymentsList.RightItems)
                {
                    if (String.Compare(item.Value, row.PaymentMethodId.ToString(), true) == 0 && !row.RestrictShippingMethods)
                    {
                        found = true;
                        break;
                    }
                }

                if (!found)
                {
                    row.Delete();
                }
            }

            // b). add selected rows to dto
            foreach (ListItem item in PaymentsList.RightItems)
            {
                bool exists = false;
                foreach (ShippingMethodDto.ShippingPaymentRestrictionRow row in shippingRow.GetShippingPaymentRestrictionRows())
                {
                    if (String.Compare(item.Value, row.PaymentMethodId.ToString(), true) == 0 && !row.RestrictShippingMethods)
                    {
                        exists = true;
                        break;
                    }
                }

                if (!exists)
                {
                    ShippingMethodDto.ShippingPaymentRestrictionRow restrictedRow = dto.ShippingPaymentRestriction.NewShippingPaymentRestrictionRow();
                    restrictedRow.PaymentMethodId         = new Guid(item.Value);
                    restrictedRow.ShippingMethodId        = shippingRow.ShippingMethodId;
                    restrictedRow.RestrictShippingMethods = false;

                    // add the row to the dto
                    dto.ShippingPaymentRestriction.Rows.Add(restrictedRow);
                }
            }
        }