Click here to Skip to main content
Click here to Skip to main content
Go to top

Repeater Paging With last and First Page Button

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

Introduction

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

Background

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
        {
            //get current page number
            object obj = this.ViewState["_CurrentPage"];

            if (obj == null)
            {
                return 0;
            }
            else
            {
                return (int)obj;
            }
        }
        set
        {
            //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;
        rptstudnet.DataBind();

        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);
        }
        else
        {
            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;
        rptstudnet.DataBind();

        return count;
    }

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

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

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

    protected void lbtnLast_Click(object sender, EventArgs e)
    {
        CurrentPage = DisplayRepeter() - 1;
        DisplayRepeter();
    }
    /// <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" 
    Width="70"></asp:Button></li>
<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" 
onclick="lbtnNext_Click"></asp:Button></li>
<li><asp:Button ID="lbtnLast" runat="server" 
class="btn btn-primary" Width="70" Text="Last" 
onclick="lbtnLast_Click"></asp:Button></li>  

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

License

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

Share

About the Author

JatinKhimani

India India
No Biography provided

Comments and Discussions

 
Questionplease provide some image type description PinmemberMember 1053192918-Feb-14 20:29 
AnswerRe: please provide some image type description PinmemberJatinKhimani23-Feb-14 18:25 
GeneralRe: please provide some image type description PinmemberNelek26-Feb-14 21:53 

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.140916.1 | Last Updated 18 Feb 2014
Article Copyright 2014 by JatinKhimani
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid