Click here to Skip to main content
15,884,472 members
Articles / Web Development / ASP.NET

GridView Pager Template

Rate me:
Please Sign up or sign in to vote.
5.00/5 (3 votes)
30 Sep 2013CPOL 52.1K   5   8
GridView pager template

I recently created a dynamic data project and needed to change its layout, most things went well until I came to changing the list page. This consisted of a Gridview and standard pager template. I had already started using bootstrap (for ease of use) so wanted to change the table to use bootstrap table classes with its standard pager. After much searching, I managed to get the table outputting correctly using CSS Friendly adapters. However, the pager was a bit lacking.

I had already developed a paging control for a different project and it looked like a fairly simple modification to get it to use the gridview.

The pagers itself is a scrolling window pager with:

  • Optional ‘First/Last’ and ‘Previous/Next’ links with easily changeable text
  • Changeable ’Pager links to show’ setting
  • Easily modifiable HTML output

Simply add the following class into your project:

Gridview pager template class

Reference it in your gridview, this is how my gridview looks:

ASP.NET
<asp:GridView ID="GridView1"
    runat="server"
    DataSourceID="GridDataSource"
    AllowPaging="True"
    AllowSorting="True"
    CssClass="table table-striped"
    AutoGenerateEditButton="True"
    AutoGenerateDeleteButton="True"
    PageSize="5" >
    <PagerTemplate>
        <asp:GridPager ID="GridViewPager1" runat="server"
            ShowFirstAndLast="True"
            ShowNextAndPrevious="True"
            PageLinksToShow="10"
            NextText="›"
            PreviousText="‹"
            FirstText="«"
            LastText="»"/>
    </PagerTemplate>
    <EmptyDataTemplate>
        There are currently no items in this table.
    </EmptyDataTemplate>
</asp:GridView>
This article was originally posted at http://development.tonygayter.com/gridview-pager-template

License

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


Written By
Web Developer
United Kingdom United Kingdom
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
Questionwhere can i see the asp:gridpager template class Pin
rmartinezr24-Aug-22 16:50
rmartinezr24-Aug-22 16:50 
QuestionUnknown server tag error Pin
Awaidus Bin Asim28-Aug-14 7:07
Awaidus Bin Asim28-Aug-14 7:07 
AnswerRe: Unknown server tag error Pin
Tony Gayter28-Aug-14 7:26
Tony Gayter28-Aug-14 7:26 
GeneralRe: Unknown server tag error Pin
Awaidus Bin Asim29-Aug-14 4:07
Awaidus Bin Asim29-Aug-14 4:07 
QuestionCode missing Pin
briankitt29-Sep-13 16:14
briankitt29-Sep-13 16:14 
AnswerRe: Code missing Pin
Tony Gayter30-Sep-13 0:41
Tony Gayter30-Sep-13 0:41 
GeneralRe: Code missing Pin
briankitt30-Sep-13 5:26
briankitt30-Sep-13 5:26 
GeneralRe: Code missing Pin
kbalint4-Apr-14 3:08
kbalint4-Apr-14 3:08 

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.