[SOLVED] How to implement custom paging in gridview in ASP.NET using C# with data modified in code-behind


I have looked-up custom paging with gridviews in ASP.NET, but it seemed to work only for displaying exact same rows from the database to the web page.

In my case, I currently use default gridview paging to select all rows from the database, then process that data in the code behind of my aspx page, and then show custom rows based on that processed data in my gridview.

My question is: I want to know how to select a certain amount of rows from the database that will reflect just enough "custom" rows for 1 page in my gridview on the web page.

Note: I process the data on the front-end and group them in custom rows based on a common, same FKID value.

Would really appreciate the help,


Does each FKID-value have the same amount of rows in your table? I assume this isn’t the case.

I think your options are the following:

  1. You could leave your logic as-is. If the performance isn’t too bad, I think this is the easiest solution.

  2. Create a view at database-level. This view should then directly provide records as you need them as a row in your GridView. This puts the paging-logic at the database-level, and is performance-wise the fastest option I think.

  3. Do the same as option 2, but then at your application level. That could work this way: Construct a select query that gives you the count of distinct FKID values, and a query that can give you a list of FKID values based on a ‘startindex’ and ‘number of rows’. For each FKID returned, fire another query fetching the corresponding rows. Apply your logic, and return the page of rows to your GridView.

Answered By – tim-

Answer Checked By – Robin (BugsFixing Admin)

Leave a Reply

Your email address will not be published. Required fields are marked *