Click here to Skip to main content
13,198,075 members (57,266 online)
Click here to Skip to main content
Add your own
alternative version


19 bookmarked
Posted 20 Mar 2007

Paging control for Gridview Display

, 20 Mar 2007
Rate this:
Please Sign up or sign in to vote.
A simple paging control for grid view display
Screenshot - pagingGrid.jpg


Paging Control for Gridview enables the paging control to your gridview display. Large number of data when displayed on a single screen could be clumpsy. With the paging enabled on the grid view, total data could be divided into number of pages and displayed as separate pages.

Using the code

The simple logic of paging is as follows: we maintain a global datatable, current index and a temporary datatable. First the total data to be displayed is loaded in the main Datatable. This will be done only once for a particular set of data. After the main datatable is loaded, then according to the provided no. of documents for each page, total page no. is determined and the each page is shown with the corresponding data from the main datatable.

public int currentIndex = 1; 
public DataTable mainDTable;
public DataTable tempDTable;
public int numDocs;
public int totPages = 1;
For this a temporary data table is maintained. What it does is, it fetches the selected rows from the main datatable according to the current index and the total no. of documents to be shown in each page. The grid view is cleared each time a page changes and is reloaded each time from the temp. data table which keeps on changing with the current index. The range for the data to be populated in the temp datatable is calculated as shown above as from_value and to_value. so at each instance the temp datatable consist of data from the values of fromvalue to the tovalue.
int fromValue = numDocs * (currentIndex - 1) + 1;
int toValue = currentIndex * numDocs;

Points of Interest

The important thing to remember here is the tracking of the current index. If you get it slipped then whole the logic may be useless.


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Software Developer at Nepasoft solutions, Nepal and a visionary.

You may also be interested in...


Comments and Discussions

QuestionI vote 5 star Pin
Sang-Taik Jung17-Nov-13 17:40
memberSang-Taik Jung17-Nov-13 17:40 
GeneralGood to have a Nepali Pin
Astitva2311-May-09 14:08
memberAstitva2311-May-09 14:08 
GeneralDear Mr. Wagle [modified] Pin
ring_022-Apr-07 22:29
memberring_022-Apr-07 22:29 
Keep it up buddy.

Full five for this article;)


-- modified at 4:39 Monday 23rd April, 2007

Man having 1 bit brain with parity error

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.171020.1 | Last Updated 20 Mar 2007
Article Copyright 2007 by Ram Krishna Wagle
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid