Add a Row Number to the GridView

Here’s a simple way to add a Row Number to the GridView. Just add the following tags to your <columns> section of your GridView

asp:TemplateField HeaderText="RowNumber">
<%# Container.DataItemIndex + 1 %>

and you will get the following output


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

Thanx buddy...simple and best

Danish Backer said...

Thank you...! :D

Karuna said...

Thank you it works fine

lingmaaki said...

Gridview examples....Gridview Tutorial