ASP.NET – Function to Fill Month, Date and Year into Dropdown lists
Posted
by
SAMIR BHOGAYTA
on Samir ASP.NET with C# Technology
See other posts from Samir ASP.NET with C# Technology
or by SAMIR BHOGAYTA
Published on 2010-06-29T02:12:00.001-07:00
Indexed on
2010/12/06
17:00 UTC
Read the original article
Hit count: 722
Date and Year into Dropdo
|ASP.NET – Function to Fil
{
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()));
}
}
© Samir ASP.NET with C# Technology or respective owner