public void BindMonthDropDownList()
{
List<SelectListItem> ddlMonthNames = new List<SelectListItem>();
ddlMonthNames.Add(new SelectListItem { Text
= "--Select Month--", Value = "0" });
for (int month = 1; month <= 12; month++)
{
string monthName = DateTimeFormatInfo.CurrentInfo.GetMonthName(month);
ddlMonthNames.Add(new SelectListItem { Text
= monthName, Value = month.ToString().PadLeft(2, '0') });
}
ViewBag.MonthDropDownList =
ddlMonthNames;
}
public void BindYearDropDownList()
{
List<SelectListItem> ddlMonthNames = new List<SelectListItem>();
ddlMonthNames.Add(new SelectListItem { Text
= "--Select Year--", Value = "0" });
for (int i = 2000; i <= System.DateTime.Now.AddYears(1).Year; i++)
{
ddlMonthNames.Add(new SelectListItem { Text
= i.ToString(), Value = i.ToString() });
}
ViewBag.yearDropDownList =
ddlMonthNames;
}
No comments:
Post a Comment