Click here to Skip to main content
11,414,234 members (74,893 online)
Click here to Skip to main content

Client Side Gridview Pagination using JQuery

, 10 Jun 2009 CPOL
Rate this:
Please Sign up or sign in to vote.
Client Side Gridview Paging using Jquery
2.JPG

Introduction 

Here, I would like to show how to use Client Side Gridview Pagination using Jquery Table Pagination Plugin by using Ryan Zielke.  

Using the Code

First create a folder called "images". Then paste all the image files into that folder.

1.JPG

Next, add the reference of Jquery and Plugin JavaScript file in the ASPX Page.   

<script src="jquery-1.3.2.min.js" type="text/javascript"></script>
<script src="jquery.tablePagination.0.1.js" type="text/javascript"></script>

Then add the CSS below. Here Width value of #testTable must be the same as the Width of your Gridview control.

#testTable { 
            width : 300px;
            margin-left: auto; 
            margin-right: auto; 
          }
          
           #tablePagination { 
            background-color:  Transparent; 
            font-size: 0.8em; 
            padding: 0px 5px; 
            height: 20px
          }
          
          #tablePagination_paginater { 
            margin-left: auto; 
            margin-right: auto;
          }
          
          #tablePagination img { 
            padding: 0px 2px; 
          }
          
          #tablePagination_perPage { 
            float: left; 
          }
          
          #tablePagination_paginater { 
            float: right; 
          }

Finally, add this script in your ASPX Page:

<script type ="text/javascript" >
	$(document).ready(
 	function() {
 	$('table').tablePagination({});
 	});
 	</script> 

Now, add Gridview1_PreRender method in code behind, unless during paging you cannot see the Header of Gridview. Generally, Gridview does not use tbody, thead, or tfoot tags for the table that is generated when rendered in the browser. So, for Tbody and Thead, we need to add this function:

 protected void GridView1_PreRender(object sender, EventArgs e)
 {
     GridView1.UseAccessibleHeader = false;
     GridView1.HeaderRow.TableSection = TableRowSection.TableHeader;
 }

Configuration

You can change different parameters of jquery.tablePagination.0.1.js. Below are some of the settings from the authors Site:

  • firstArrow - Image - Pass in an image to replace default image.
    Default: (new Image()).src="./images/first.gif"
  • prevArrow - Image - Pass in an image to replace default image.
    Default: (new Image()).src="./images/prev.gif"
  • lastArrow - Image - Pass in an image to replace default image.
    Default: (new Image()).src="./images/last.gif"
  • nextArrow - Image - Pass in an image to replace default image.
    Default: (new Image()).src="./images/next.gif"
  • rowsPerPage - Number - used to determine the starting rows per page.
    Default: 5
  • currPage - Number - This is to determine what the starting current page is. Default: 1
  • optionsForRows - Array - This is to set the values on the rows per page.
    Default: [5,10,25,50,100]
  • ignoreRows - Array - This is to specify which 'tr' rows to ignore. It is recommended that you have those rows be invisible as they will mess with page counts.
    Default: [].

For the Future Release of Table Pagination Plugin

History

  • 10th June, 2009: Initial post

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

sagnik mukherjee
Web Developer
India India
I am from India, currently i am working in Microsoft Platform for building web and mobile applications.
Follow on   Twitter

Comments and Discussions

 
Questionhide table pagination Pin
Member 10780022, 5-Feb-15 1:58
memberMember 107800225-Feb-15 1:58 
Questionmy 5 :) Pin
King Fisher, 12-Jan-15 3:05
professionalKing Fisher12-Jan-15 3:05 
QuestionPlease reply Pin
Mahendra H. yadav, 4-Jul-14 4:59
memberMahendra H. yadav4-Jul-14 4:59 
QuestionPagination work fine but the page number not shown in dropdownlist. It show in a textbox Pin
maharajothi, 20-May-14 20:53
professionalmaharajothi20-May-14 20:53 
QuestionMy vote is 5 Pin
aaronjave, 16-Apr-13 7:24
memberaaronjave16-Apr-13 7:24 
Questionpagination works if only the window is refreshed Pin
kasirajan -, 7-Apr-13 23:52
memberkasirajan -7-Apr-13 23:52 
QuestionContentPlace Holder Pin
Reima Cram, 24-Jan-13 21:04
memberReima Cram24-Jan-13 21:04 
QuestionThanks Pin
avinashinde2020, 28-Nov-12 3:04
memberavinashinde202028-Nov-12 3:04 
QuestionThis doesnt work if we do a server side Data Bind Pin
msdnexpert, 7-Oct-11 5:19
membermsdnexpert7-Oct-11 5:19 
AnswerRe: This doesnt work if we do a server side Data Bind Pin
pkaminiv, 18-May-12 0:20
memberpkaminiv18-May-12 0:20 
QuestionPaging in number Pin
megha.khamar@gmail.com, 18-Aug-11 0:59
membermegha.khamar@gmail.com18-Aug-11 0:59 
GeneralPrerender method for DataGrid Pin
u4bharat, 10-Jun-11 2:51
memberu4bharat10-Jun-11 2:51 
GeneralAdd Pager to a Repeater Pin
nipunasilva, 23-May-11 21:52
membernipunasilva23-May-11 21:52 
GeneralMy vote of 5 Pin
nipunasilva, 23-May-11 21:50
membernipunasilva23-May-11 21:50 
QuestionMissing Images Pin
jagman82, 3-Jan-11 5:43
memberjagman823-Jan-11 5:43 
Generalgridview paging using javascript only not by JQUERY Pin
nilesh.d.mankar, 27-Dec-10 5:31
membernilesh.d.mankar27-Dec-10 5:31 
GeneralMy vote of 4 Pin
bhavasinchana, 2-Dec-10 4:47
memberbhavasinchana2-Dec-10 4:47 
Questionpaging above the grid Pin
Chella S, 18-Nov-10 20:57
memberChella S18-Nov-10 20:57 
AnswerRe: paging above the grid Pin
sagnik mukherjee, 21-Nov-10 23:37
membersagnik mukherjee21-Nov-10 23:37 
GeneralRe: paging above the grid Pin
Chella S, 22-Nov-10 21:39
memberChella S22-Nov-10 21:39 
GeneralRe: paging above the grid Pin
sagnik mukherjee, 23-Nov-10 7:33
membersagnik mukherjee23-Nov-10 7:33 
GeneralRe: paging above the grid Pin
Chella S, 25-Nov-10 0:49
memberChella S25-Nov-10 0:49 
Question2grid view and 2 table in one page Pin
majid_3ma, 2-Nov-10 21:17
membermajid_3ma2-Nov-10 21:17 
Questionpaging with dynamic html table Pin
Guru_yogi, 6-Nov-09 2:39
memberGuru_yogi6-Nov-09 2:39 
AnswerRe: paging with dynamic html table Pin
NeoAlchemy, 8-Nov-09 16:15
memberNeoAlchemy8-Nov-09 16:15 

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 | Terms of Use | Mobile
Web04 | 2.8.150427.2 | Last Updated 10 Jun 2009
Article Copyright 2009 by sagnik mukherjee
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid