/// <summary> /// Before bind data elements to droplist city. /// </summary> /// <param name="sender">Object sender : ddlCity.</param> /// <param name="e">EventArgs e.</param> protected void OnCityDataBinding(Object sender, EventArgs e) { // Get droplist element from paren control. DropDownList ddlCountry = fvAddress.FindControl("ddlCountry") as DropDownList; // If user have set country, bind cities from that country to second droplist. if (ddlCountry.SelectedIndex > 0) { DropDownList ddlCity = sender as DropDownList; Guid selectedCountry = Guid.Empty; if (Guid.TryParse(ddlCountry.SelectedValue, out selectedCountry)) { ddlCity.DataSource = AddressRepository.GetAllCountryCities(selectedCountry); } } }
public List <KeyValuePair <Guid, String> > GetAllCountryCities(Guid countryID) { return(AddressRepository.GetAllCountryCities(countryID) .Select(s => new KeyValuePair <Guid, String>(s.CityID, s.Name)) .ToList()); }