protected void Page_Load(object sender, EventArgs e) { Country[] countryList = apiManager.GetCountryList(); foreach (var country in countryList) { ListItem li = new ListItem(); li.Text = country.name; li.Value = country.name; // DDLCountry.Items.Add(li); DDLCurrency.Items.Add(li); } updateWeather(); }
protected void Page_Load(object sender, EventArgs e) { updateQueryStrings(); string currency = ""; Country[] countryList = apiManager.GetCountryList(); foreach (var country in countryList) { if (country.name == countrySearch) { currency = country.currencies[0].code; } ListItem li = new ListItem(); li.Text = country.name; li.Value = country.name; // DDLCountry.Items.Add(li); // DDLCountry.Items.Add(li); } if (countrySearch == "Singapore") { currency = "SGD"; } int day = 0;; Rates rates = apiManager.GetCurrency(); foreach (PropertyDescriptor descriptor in TypeDescriptor.GetProperties(rates)) { string name = descriptor.Name; object value = descriptor.GetValue(rates); if (name == "SGD") { sgdRate = float.Parse(value.ToString()); } ListItem li = new ListItem(); li.Text = name; li.Value = name; DDLCurrency.Items.Add(li); //Console.WriteLine("{0}={1}", name, value); } if (!IsPostBack) { try { object item = rates.GetType().GetProperty(currency).GetValue(rates, null); DDLCurrency.SelectedValue = currency; updateCost(DDLCurrency.SelectedItem.Text, DDLStyle.Text, float.Parse(item.ToString())); } catch (Exception ex) { DDLCurrency.SelectedValue = "SGD"; updateCost(DDLCurrency.SelectedItem.Text, DDLStyle.Text, sgdRate); } } }