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 < 12; 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 <= totalDays; 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 <= Convert.ToInt32(DateTime.Now.Year); intLoop++)
{
ddlList.Items.Add(new ListItem(intLoop.ToString(), intLoop.ToString()));
}
}
1 comment:
Very useful bit of code. Thanks for posting.
Post a Comment