Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# Dropdown items 0 - 100 without adding each item?

Tags:

c#

.net

Sorry if this is a dumb question ... I'm just trying to learn the best way to do it. Basically I want to have a dropdown list with values blank and then 0 - 100.

Whats is the best way to do this without manually entering each one. I imagine it is through some form of a list bound to the dropdown.

Thankyou in advance for the help.

like image 801
bumble_bee_tuna Avatar asked Nov 29 '22 04:11

bumble_bee_tuna


1 Answers

Here is one way of doing it:

ddl.Items.AddRange(Enumerable.Range(0, 100).Select (e => new ListItem(e.ToString())).ToArray());
like image 132
Magnus Avatar answered Dec 16 '22 04:12

Magnus