I am not able to get the desired result from a post that I am following to implement on my website. I want to do paging using the repeater control.
I am referring to this method (post) for implementing the (post of c sharp corner)
Description of problem:
- I don't want to implement the stored procedure feature hence I have only followed this post till step number # 3.
I have set the page size as 1 and I have 4 records in the database.
The paging repeater (repeater1 as per the code) has correctly shown 4 pages
Problem is that when the last page is clicked it shows no result. To explain the exact problem, I have made the incorrect code live on this link.
A list of all 4 posts can be viewed on this link. (scroll till the bottom of the page)
What might be the main issue which is causing this issue?
Steps taken by me: 1. I have tried setting the pdsData.CurrentPageIndex = 0; to 1 at row # 41 (step 3) - problem not solved 2. I tried setting
ViewState["PageNumber"] = Convert.ToInt32(e.CommandArgument);
as
ViewState["PageNumber"] = Convert.ToInt32(e.CommandArgument)+1;
problem is still the same (row number 61 or step 3)
I am open to alternatives to achieving an efficient paging using repeater control. I am using asp.net version 4.5.
I believe the problem in the code is with for loop:
This loop has been initialized as i=1 while index usually starts with ZERO. I have changed this initialization as i=0. This made my for loop like:
This fixed the issue of the extra page which is blank.
Note: This solution will initiate the pager (page numbers in the bottom) start from 0, 1, 2, etc instead of 1, 2, 3, and so on.
I fixed this by adding one (+1) to the bound filed in the .aspx page. see the example below:
These edits have made the paging using repeater bug-free and smooth.