How to fill date,month and year in ASP.NET DropDownlList?
i am doing a party site now,so i want to use dropdownlist frequently an some pages. to avoid code repeating i wrote a separate class file to fill dropdownlist. in that class file the programmer just send three dropdownlist it returned with values.
Class File
public void FillYearMonthDayDropDown(DropDownList ddlDay, DropDownList ddlMonth, DropDownList ddlYear)
{
ddlDay.Items.Clear();
ddlMonth.Items.Clear();
ddlYear.Items.Clear();
ddlMonth.Items.Add("MONTH");
ddlDay.Items.Add("DAY");
ddlYear.Items.Add("YEAR");
for (int i = 1; i <= 12; i++) { ddlMonth.Items.Add(i.ToString()); } for (int i = 1; i <= 31; i++) { ddlDay.Items.Add(i.ToString()); } for (int i = Convert.ToInt32(DateTime.Now.Year-16); i > Convert.ToInt32(DateTime.Now.Year-80); i--)
{
ddlYear.Items.Add(i.ToString());
}
}
No comments:
Post a Comment