Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Populate asp.net dropdownlist with number

A simple query , i want to populate the dropdownlist with number starting from 17 to 90 , and the last number should be a string like 90+ instead of 90. I guess the logic will be using a for loop something like:

for (int a = 17; a <= 90; a++)
        {
            ddlAge.Items.Add(a.ToString());
        }

Also I want to populate the text and value of each list item with the same numbers. Any ideas?

like image 568
Mr A Avatar asked Dec 02 '22 00:12

Mr A


1 Answers

for (int i = 17; i < 90; i++)
{
    ddlAge.Items.Add(new ListItem(i.ToString(), i.ToString()));
}
ddlAge.Items.Add(new ListItem("90+", "90"));
like image 82
Tim Schmelter Avatar answered Dec 05 '22 05:12

Tim Schmelter