Sequence Number in DataGrid with Paging
In my previous article( Generating Sequence Number in DataGrid) ,
i have explained how to generate sequence number (row
number) in a DataGrid. This method can be easily implemented in
DataGrid if there is no paging involved in that DataGrid. But same
wont work in DataGrid, if paging is also there in DataGrid. To know
how to do paging in DataGrid, refer this article Paging in DataGrid
If you implement this method, in the all the
pages Sequence number will start from one only. But our requirement
is not that, sequence number has to continue in all the pages.
For example if i am going to second page with
Pagesize 10, then sequence number should start from 11.
To achieve this result we need to slightly tweak our previous
method. Code snippet for implementing this method
runat="server" PagerStyle-Mode=NumericPages PageSize="10"
<asp:boundcolumn runat="server" DataField="CompanyName"
<asp:boundcolumn runat="server" DataField="Address"
Tweak in the code is very simple, instead
of only using container.itemindex to get the sequence number. You need to
use Pagesize and currentpageindex to find out the starting number of that
page and then add container.itemindex to that. Then your sequence number will
look like the following fig for second page,