Gridview add / show srno : How to add or show auto-generated incremented serial number in gridview


Overview: Adding an auto-generated serial number, show first column as Sr no in Gridview  In this article will explain how to add or show auto increment the serial number.i.e. add or show auto-generated serial no (Sr no) as first column in gridview control.

Serial number Sr no  can be added by using DataItemIndex in Gridview control.

DataItemIndex : Gets the index of the DataItem in the underlying DataSet.


Using DataItemIndex, i.e  By adding code inside gridview you will get an auto-generated serial number. You may notice in below code we had incremented  DataItemIndex  by one ( 1 ), because DataItemIndex property is the zero-based index, so to starts from one 1 we incremented it by one.

Finally, our code  Gridview will look like this, where the first column of gridview is an auto-generated serial number.

Yup, now we are done with auto-generated increamented serial number 😉

You must check these articles:

Hope you enjoyed this tutorial. If you have any recommendations, please let us know what you think in the comment section below! See you again next time!