Click here to Skip to main content
12,695,049 members (33,923 online)
Click here to Skip to main content
Add your own
alternative version


8 bookmarked

Repeater Paging With last and First Page Button

, 17 Feb 2014 CPOL
Rate this:
Please Sign up or sign in to vote.
This tip provides the repeter paging with First and Last Page button


Repeater paging provides the Paging facility in Repeater which was not default given into Repeater control of the ASP.NET.


This includes the Four Linkbuttons, the names of which are First, Previous, Next, Last respectively and give the paging as per your page requirement like display 5, 10, 15... as you need.

Using the Code  

For using this one, you need to integrate this code in your CS file and add this function, then call it wherever you need to display your data.

You have to put four link buttons between your Repeater <separatortemplate> tag.

    /// <summary>
    /// ////////////////////////////////////////////////////////////////
    /// </summary>
    public int CurrentPage
            //get current page number
            object obj = this.ViewState["_CurrentPage"];

            if (obj == null)
                return 0;
                return (int)obj;
            //set in viewstate the current page number
            this.ViewState["_CurrentPage"] = value;

    public int DisplayRepeter()
        SqlParameter[] p = new SqlParameter[1];
        p[0] = new SqlParameter("projectid", drpprojectlist.SelectedValue);
        DataSet ds = cm.SP_Select("SP_StudentSelectByProject", p);
        rptstudnet.DataSource = ds;

        PagedDataSource pds = new PagedDataSource();

        pds.DataSource = ds.Tables[0].DefaultView;
        pds.AllowPaging = true;
        pds.PageSize = 6;
        int count = pds.PageCount;

        pds.CurrentPageIndex = CurrentPage;

        if (pds.Count > 0)
            lbtnPrev.Visible = true;
            lbtnNext.Visible = true;
            lbtnFirst.Visible = true;
            lbtnLast.Visible = true;

            lblStatus.Text = "Page " + Convert.ToString
            (CurrentPage + 1) + "of" + Convert.ToString(pds.PageCount);
            lbtnPrev.Visible = false;
            lbtnNext.Visible = false;
            lbtnFirst.Visible = false;
            lbtnLast.Visible = false;

        lbtnPrev.Enabled = !pds.IsFirstPage;
        lbtnNext.Enabled = !pds.IsLastPage;
        lbtnFirst.Enabled = !pds.IsFirstPage;
        lbtnLast.Enabled = !pds.IsLastPage;

        rptstudnet.DataSource = pds;

        return count;

    protected void lbtnPrev_Click(object sender, EventArgs e)
        CurrentPage -= 1;

    protected void lbtnNext_Click(object sender, EventArgs e)
        CurrentPage += 1;

    protected void lbtnFirst_Click(object sender, EventArgs e)
        CurrentPage = 0;

    protected void lbtnLast_Click(object sender, EventArgs e)
        CurrentPage = DisplayRepeter() - 1;
    /// <summary>
    /// /////////////////////////////////////////////////////////
    /// </summary>  

Add this link button in your source code of .ASPX page between repeater separatortemplate.

<li><asp:Button ID="lbtnFirst" runat="server" 
    class="btn btn-primary" Text="First"  onclick="lbtnFirst_Click" 
<li><asp:Button ID="lbtnPrev" runat="server" 
class="btn btn-primary" Text="Prev" 
onclick="lbtnPrev_Click" Width="70"></asp:Button></li>
<li><asp:Button ID="lbtnNext" runat="server" 
class="btn btn-primary" Width="70" Text="Next" 
<li><asp:Button ID="lbtnLast" runat="server" 
class="btn btn-primary" Width="70" Text="Last" 

Made changes in the above code as per your requirements like changing the StoreProcedure, etc.


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


About the Author

Software Developer (Junior) THOMSON REUTERS
India India
No Biography provided

You may also be interested in...

Comments and Discussions

Questionplease provide some image type description Pin
Member 1053192918-Feb-14 21:29
memberMember 1053192918-Feb-14 21:29 
AnswerRe: please provide some image type description Pin
JatinKhimani23-Feb-14 19:25
memberJatinKhimani23-Feb-14 19:25 
GeneralRe: please provide some image type description Pin
Nelek26-Feb-14 22:53
memberNelek26-Feb-14 22:53 

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.

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170118.1 | Last Updated 18 Feb 2014
Article Copyright 2014 by JatinKhimani
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid