Auto Generate Row Number in ASP.NET ListView

One of my blog readers Robert asked me a question. Is it possible to create a counter field or an auto-generated Row Number in an ASP.NET ListView.

The solution is to add <%# Container.DataItemIndex + 1 %> to the ItemTemplate of the ListView as shown below:

ListView Row Number

The output with the auto generated serial number/row number is as shown below:

ListView Row Number

If you are working with the ASP.NET GridView, check this post of mine ASP.NET GridView Tips and Tricks series






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.

4 comments:

Edward said...

Thanks, this is just what I was looking for!

nhp91 said...

Thank you, i'm looking for this

Anonymous said...

OMG, i was two days looking for a solution for my problem (using radiobutton to select a row in a listview and get the row index clicking in a button) and this is just what I was looking for.

Unknown said...

Thank You Sir!