Populate drop down list using forloop in C#

Create a drop down list on your page named BirthYearDropDownList

for (int i= 1900; i< DateTime.Now.Year; i++) 
{ 
    BirthYearDropDownList.Items.Add(i.ToString()); 
} 
 
if (!IsPostBack) 
{ 
    BirthYearDropDownList. SelectedIndex = 85; 
}

Enjoyed this post? Share it!

 

Leave a comment

Your email address will not be published.