I'm using a List in ASP.NET 3.5/C# to filter an existing list of dates (about 20 in total) on a specific month. So if a user selects a year of 2010 (ddlFromYear.SelectedItem.Text == 2010) then the returned list would consist of only 8 months because we only go up to August.
My question is - how do I output the DateTime as an int, or even preferrably a Month, e.g. "August". That way when I'm binding another DropDown I can list out all the months (January, February...) which as I mentioned would be determined by years (2009, 2010...)
int yearSelected;
bool success = Int32.TryParse(ddlFromYear.SelectedItem.Text, out yearSelected);
if (success)
{
List<DateTime> datesSelected = new List<DateTime>();
datesSelected =
(from n in dates
where n.Year.Equals(yearSelected)
select n).ToList();
dateMonths.Sort();
ddlFromMonth.Items.Clear();
ddlFromMonth.DataSource = datesSelected;
ddlFromMonth.DataBind();
}