0

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:

  1. I don't want to implement the stored procedure feature hence I have only followed this post till step number # 3.
  2. I have set the page size as 1 and I have 4 records in the database.

  3. The paging repeater (repeater1 as per the code) has correctly shown 4 pages

  4. 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.

  5. 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.

halfer
  • 18,701
  • 13
  • 79
  • 158
Jay
  • 7
  • 1

1 Answers1

0

I believe the problem in the code is with for loop:

for (int i = 1; i <= pdsData.PageCount; i++)  
alPages.Add((i).ToString());

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:

for (int i = 0; i < pdsData.PageCount; i++)  
alPages.Add((i).ToString());

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:

<%#Int32.Parse( Container.DataItem.ToString())+1%>

These edits have made the paging using repeater bug-free and smooth.

Jay
  • 7
  • 1