Adding forward & backward page hyperlink

doramail05
doramail05 used Ask the Experts™
on
i try to add another hyperlink ' .. ' in front and behind the page numbers
..10 11 12 13 14 15 16 17 18 19 20 ..
by clicking it, it will navigate to ---  > .. 21 22 23 24 25 26 27 28 29 30 ..
based on the article below :

http://www.c-sharpcorner.com/UploadFile/rizwan328/DataListCustomPaging01112009021450AM/DataListCustomPaging.aspx
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
if you following the article
then add 2 LinkButtons  Next10 Previous10

and event handler

protected void lbtnNext10_Click(object sender, EventArgs e)
    {
 
        CurrentPage += 10;
        this.BindItemsList();
 
    }

protected void lbtnPrevious10_Click(object sender, EventArgs e)
    {
 
        CurrentPage -= 10;
        this.BindItemsList();
 
    }

Author

Commented:
i try to hide the .. (previous10) when the page is first page and also hide .. (next10) when the page is the last page,
it works during page load (first time), but when navigating through the pages, it did not work.
protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                this.BindItemsList();
            }

            if (_PageDataSource.IsFirstPage)
            {
                lbtnPrevious10.Visible = false;
            }

            if (_PageDataSource.IsLastPage)
            {
                lbtnNext10.Visible = false;
            }

        }

Open in new window

change BindItemsList() function

add

this.lbtnPrevious10.Enabled = !_PageDataSource.IsFirstPage;
this.lbtnNext10.Enabled = !_PageDataSource.IsLastPage;

private void BindItemsList()
    {
 
        DataTable dataTable = this.GetDataTable();
        _PageDataSource.DataSource = dataTable.DefaultView;
        _PageDataSource.AllowPaging = true;
        _PageDataSource.PageSize = 10;
        _PageDataSource.CurrentPageIndex = CurrentPage;
        ViewState["TotalPages"] = _PageDataSource.PageCount;
 
        this.lblPageInfo.Text = "Page " + (CurrentPage + 1) + " of " + _PageDataSource.PageCount;
        this.lbtnPrevious.Enabled = !_PageDataSource.IsFirstPage;
        this.lbtnNext.Enabled = !_PageDataSource.IsLastPage;
        this.lbtnFirst.Enabled = !_PageDataSource.IsFirstPage;
        this.lbtnLast.Enabled = !_PageDataSource.IsLastPage;
this.lbtnPrevious10.Enabled = !_PageDataSource.IsFirstPage;
this.lbtnNext10.Enabled = !_PageDataSource.IsLastPage;
 
        this.dListItems.DataSource = _PageDataSource;
        this.dListItems.DataBind();
        this.doPaging();
    }

Open in new window

Exploring ASP.NET Core: Fundamentals

Learn to build web apps and services, IoT apps, and mobile backends by covering the fundamentals of ASP.NET Core and  exploring the core foundations for app libraries.

or add custom logic

for pages 1 to 10 you don't require Previous10

so in BindItemsList()

add

if(CurrentPage>10)
this.lbtnPrevious10.Enabled=true;
else
this.lbtnPrevious10.Enabled=false;

same with next10

Author

Commented:
great, thanx for that.

Author

Commented:
a moment pls,
while at record 96 , i entered .. (next10) , it shoot to
116 of 110 records
without any records showing.

add custom logic

for pages 1 to 10 you don't require Previous10

so in BindItemsList()

add

if(CurrentPage>10)
this.lbtnPrevious10.Enabled=true;
else
this.lbtnPrevious10.Enabled=false;

same with next10

Author

Commented:
did not comment out the following code just now

//this.lbtnPrevious10.Enabled = !_PageDataSource.IsFirstPage;
       
//this.lbtnNext10.Enabled = !_PageDataSource.IsLastPage;

Author

Commented:
i dunno why it did not work again,

both previous10 and next10 is disable after clicking to page 11


        if (CurrentPage > 10)
            this.lbtnPrevious10.Enabled = true;
        else
            this.lbtnPrevious10.Enabled = false;

        if (CurrentPage < 10)
            this.lbtnNext10.Enabled = true;
        else
            this.lbtnNext10.Enabled = false;

dl-custom-pagin.bmp

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial