Click here to Skip to main content
Click here to Skip to main content

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

Introduction

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.


License

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.

Comments and Discussions

 
QuestionI vote 5 star PinmemberSang-Taik Jung17-Nov-13 17:40 
GeneralGood to have a Nepali PinmemberAstitva2311-May-09 14:08 
GeneralDear Mr. Wagle [modified] Pinmemberring_022-Apr-07 22:29 

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

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

| Advertise | Privacy | Mobile
Web04 | 2.8.140721.1 | Last Updated 20 Mar 2007
Article Copyright 2007 by Ram Krishna Wagle
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid