protected void DDLFromDataBind(object sender, EventArgs e) { FromYearsDDL.DataSource = FromYears; FromYearsDDL.DataValueField = "Key"; FromYearsDDL.DataTextField = "Key"; FromYearsDDL.SelectedValue = FromYears.FirstOrDefault(y => y.Value).Key; }
private void InitToYears() { ToYears = new Dictionary <string, bool>(); //get the selected FromYear Value int minToYear = Convert.ToInt32(FromYears.FirstOrDefault(dict => dict.Value).Key); //make sure ToYears is at least FromYears if (minToYear < Convert.ToInt32(FromYears.Min(k => k.Key))) { minToYear = Convert.ToInt32(FromYears.Min(k => k.Key)); } IEnumerable <int> toRange = Enumerable.Range(minToYear, MaxYear - minToYear); foreach (var toYear in toRange) { ToYears.Add(toYear.ToString(), toYear == (DateTime.Now.Year + 2)); } }