Populate ASP.NET ListBox with Sequential Numbers using LINQ

Usually when one thinks of populating a control like a ListBox with sequential numbers, the first thing that comes to a developers mind is to use a for loop. However with the LINQ Range Operator, generating a sequence of number is quite simple.

Let us see how to use the LINQ Range Operator to populate an ASP.NET ListBox with a Sequence of Numbers.

LINQ Range

As you can see, just a line of code and your ListBox is populated with a sequence of numbers from 1 to 30

LINQ Range

About The Author

Suprotim Agarwal
Suprotim Agarwal, Developer Technologies MVP (Microsoft Most Valuable Professional) is the founder and contributor for DevCurry, DotNetCurry and SQLServerCurry. He is the Chief Editor of a Developer Magazine called DNC Magazine. He has also authored two Books - 51 Recipes using jQuery with ASP.NET Controls. and The Absolutely Awesome jQuery CookBook.

Follow him on twitter @suprotimagarwal.


Anonymous said...

i thing that you write for making your site big. because many time i found that topic are too small.

are their any good thing whenever article not come in search.

in both case i am right.

Suprotim Agarwal said...

:) Articles being being or small doesn't matter. I share practical solutions which I encounter during my consulting assignments. If I stumbled across a problem, there is a possibility that someone else could have the same issue, and hopefully my solution could help the ones who need it!

I am not sure what you meant by the search thing. Could you rephrase it?