ASP.NET – Function to Fill Month, Date and Year into Dropdown lists
- by SAMIR BHOGAYTA
public void fillMonthList(DropDownList ddlList)
{
ddlList.Items.Add(new ListItem("Month", "Month"));
ddlList.SelectedIndex = 0;
DateTime month = Convert.ToDateTime("1/1/2000");
for (int intLoop = 0; intLoop
{
DateTime NextMont = month.AddMonths(intLoop);
//ddlList.Items.Add(new ListItem(NextMont.ToString("MMMM"), NextMont.Month.ToString()));
ddlList.Items.Add(new ListItem(NextMont.ToString("MMMM"), NextMont.ToString("MMMM")));
}
}
public void fillDayList(DropDownList ddlList)
{
ddlList.Items.Add(new ListItem("Day", "Day"));
ddlList.SelectedIndex = 0;
int totalDays = DateTime.DaysInMonth(DateTime.Now.Year, DateTime.Now.Month);
for (int intLoop = 1; intLoop
{
ddlList.Items.Add(new ListItem(intLoop.ToString(), intLoop.ToString()));
}
}
public void fillYearList(DropDownList ddlList)
{
ddlList.Items.Add(new ListItem("Year", "Year"));
ddlList.SelectedIndex = 0;
int intYearName = 1900;
for (int intLoop = intYearName; intLoop
{
ddlList.Items.Add(new ListItem(intLoop.ToString(), intLoop.ToString()));
}
}