How to create a DropDownList displaying years in asp.net

ASP.NET DropDownList Years

The following asp.net c# example code demonstrate us how can we display a list of years in
a DropDownList server control. Many web developers want to avoid TextBox to collect a year from
web users. To select a year from DropDownList is very easy and error free way. Web visitors can select a year
from a drop down list without writing content on TextBox control.

In the bellow example code, we populated a DropDownList with 11 years. We populated the DropDownList with
previous 5 years and future 5 years and current year based on the current year.
At first we create a variable to hold the current year from system DateTime object. Then we subtract 5
years and Add 5 years with the present year integer value to loop through it.
Finally, DropDownList render items with 11 years.