Bind year in Dropdown List is very easy but if you bind it statically it will create a problem for the next year so it should be dynamic upto the current year.
Here I am giving the function to bind the dropdownlist upto current year.
Here I am giving the function to bind the dropdownlist upto current year.
public void FillYearDropDown()
{
int Year;
int StartYear = 2010;
int EndYear = DateTime.Now.Year;
drpYear.Items.Clear();
for (Year = StartYear; Year <= EndYear; Year++)
{
drpYear.Items.Add(Year.ToString());
}
drpYear.Items.Insert(0, "--Select Year--");
}
{
int Year;
int StartYear = 2010;
int EndYear = DateTime.Now.Year;
drpYear.Items.Clear();
for (Year = StartYear; Year <= EndYear; Year++)
{
drpYear.Items.Add(Year.ToString());
}
drpYear.Items.Insert(0, "--Select Year--");
}
Here you can change the StartYear variable as per your requirement.
No comments:
Post a Comment