I’m stuck at trying to generate a dropdownlist where i have both year and month showing.
The dropdown must have 1 year showing like below.
- “Nov 2012”
- “Oct 2012”
- “Sep 2012”
- “Aug 2012”
- “Jul 2012”
- “Jun 2012”
- “May 2012”
- “Apr 2012”
- “Mar 2012”
- “Feb 2012”
- “Jan 2012”
- “Des 2011”
That should be one year of months.
I’m using this javascript to submit on the dropdownlist:
$('.dropdownMonthYear').change(function ()
{
var values = $('.dropdownMonthYear').val().split(",");
var month = values[0];
var year = values[1];
window.location = '/Garage/Top10Cars.aspx?month=' + month + '&year=' + year;
});
Codebehind:
month = Convert.ToInt32(Request.QueryString["month"]);
year = Convert.ToInt32(Request.QueryString["year"]);
Anyone know how this can be done?
This is one way using
Linq:The
Rangeis similar to a for-loop. In theSelecti’m creatingListItemsfrom theDateTimes(starting today, going back one month each loop).ToStringtakes a format string which converts the datetime to a string with your specified format.Standard Date and Time Format Strings
If you also want to set the ListItem’s
Valueproperty to the month number(f.e. 1 for january):