Tuesday, June 9, 2009

Load Years and Month to Drop down list Easely C#

public void LoadDDLYears(DropDownList ddlYear)
{
for (int i = 30; i > -30; i--)
{
ddlYear.Items.Add(System.DateTime.Now.AddYears(i).Year.ToString());
}
ddlYear.SelectedValue = System.DateTime.Now.Year.ToString();
}

public void LoadMonth(DropDownList ddlMonth)
{
DateTimeFormatInfo dtfi = new DateTimeFormatInfo();
for (int month = 1; month < 13; month++)
{
ListItem li = new ListItem();
li.Text = dtfi.GetMonthName(month);
li.Value = month.ToString();
ddlMonth.Items.Add(li);
}
}

No comments: