Get list of months from <DateTime>
I use List in ASP.NET 3.5 / C # to filter an existing list of dates (about 20 in total) in a specific month. Therefore, if the user selects the year 2010 (ddlFromYear.SelectedItem.Text == 2010), then the returned list will consist of only 8 months, because we go only to August.
My question is: how can I output DateTime as int, or even better than a month? "August". Thus, when I link another DropDown, I can list all the months (January, February ...), which, as I mentioned, will 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();
}
+3
2 answers