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

4 comments:

  1. Thanks, this is just what I was looking for!

    ReplyDelete
  2. Thank you, i'm looking for this

    ReplyDelete
  3. 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.

    ReplyDelete