Auto Increment Row Value In Asp.net MVC WebGrid

Updated on     Kisan Patel

Problem:

How to Implement row number in mvc3 webgrid along with paging?
How to display row number in MVC WebGrid?
How to Display Auto Increment Row Value In Asp.net MVC WebGrid Using C#.Net?

Solution:

If you want to display an index of the row independently of WebGrid then use below code:

grid.Column(header: "RowNumber", format: item => item.WebGrid.Rows.IndexOf(item) + 1)

But if you want to display an index of the row for whole data of WebGrid then use below code:

grid.Column(header: "Sr. No.",format: item => item.WebGrid.Rows.IndexOf(item) + 1 + Math.Round(Convert.ToDouble(grid.TotalRowCount / grid.PageCount) / grid.RowsPerPage) * grid.RowsPerPage * grid.PageIndex)

row-number-MVC-WebGrid


ASP.NET MVC

Leave a Reply