Click here to Skip to main content
15,891,607 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Dear All,

I have a list of candidates and i'm using "Previous" and "Next" button to view candidates.

But for last page, i want to disable "Next" button.

And i dont want to use/create new variable/member as "Total No. of Records".

What I have tried:

private void ValidatePagination()
        {
            if (grdCandidate.Items.Count < ResultsPerPage || grdCandidate.Items.Count == 0)
                btnNext.Enabled = false;
            else
                btnNext.Enabled = true;

            if (_pageNumber == 1)
                btnPrevious.Enabled = false;
            else
                btnPrevious.Enabled = true;
        }


this code works fine, if grid count is lessthen max count or eqal to zero.

but for the last page, as its shows zero records.. its working fine.. but i dont want to allow user to get empty grid on last page.

for eg:
there are 10 records..

for page1 its shows 5 records
for page2 it will show next 5 records
for page3 it is showing 0 records...

i dont want to show zero rocords/empty gird to the user at the last page. How to disable the "Next" button here(on page2 but not on page3).


Can any one please help me...


Thanks
Posted
Updated 27-Feb-17 1:17am
v2

you will get the pageIndex when user click on page no

if (_pageNumber*5== 5) // if _pageNumber=1
{
btnNext.Enabled = false;
btnPrevious.Enabled = false;
}

 if (_pageNumber* 5 >= 21)//Total Record 21
            {
                btnNext.Enabled = false;
                btnPrevious.Enabled = true;
            }
            else
            {
                btnNext.Enabled = true;
            }

Try this hope it will help you.
 
Share this answer
 
v3
If you check the "count" that you refer to, then you can set the button state.
 
Share this answer
 
C#
private void ValidatePagination()
       {
           if (grdCandidate.Items.Count < ResultsPerPage || grdCandidate.Items.Count == 0)
               btnNext.Enabled = false;
           else
               btnNext.Enabled = true;

           if (_pageNumber == 1)
               btnPrevious.Enabled = false;
           else
               btnPrevious.Enabled = true;

           if (SearchCandidates(_pageNumber + 1).Count() == 0)
               btnNext.Enabled = false;//works great
       }
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900