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

Will you give this article a +1 ? Thanks in advance

About The Author

Suprotim Agarwal
Suprotim Agarwal, ASP.NET Architecture MVP (Microsoft Most Valuable Professional) works as an Architect Consultant and provides consultancy on how to design and develop Web applications.

Suprotim is also the founder and primary contributor to DevCurry, DotNetCurry and SQLServerCurry. He is the Editor of a Developer Magazine called DNC Magazine. He has also written two EBooks 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?