This blog shows a simple snippet of automatic binding of Days, Months, Years to a DropDownList/ListBox control.
Below following methods were used for the purpose.
For binding Days:
- System.DateTime.DaysInMonth(DateTime.Now.Year, DateTime.Now.Month).
For binding DayNames
- Method returns Total Days in a Month.
- Method returns the last day of the month.
- Doing a for-each loop to retrieve Day Names from DateTimeFormatInfo.CurrentInfo.DayNames.
For binding MonthNames
Some styling is also applied; you can uncomment those code and test the samples attached.
- Doing a for-each to retrieve Month Names from DateTimeFormatInfo.CurrentInfo.MonthNames.
The output will shown as below.
Please rate and post your comments !