[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Addding Paging to a Repeater Control

Posted on 2009-07-06
2
Medium Priority
?
588 Views
Last Modified: 2012-05-07
Hi All,

I believe I have closely following the following article to implement paging for a Repeater control but for some reason it doesn't seem to be paging to the next set of data.

http://aspnet.4guysfromrolla.com/demos/TestRepeater.aspx

My code is as follows... can anyone see anything that could be wrong?...

The only differences between the 2 are my datasource is a SQL database called by SubSonic and my object variables have different names...
<h1>Product Search Results</h1>
<table width="100%" border="0">
   <tr>
      <td>  Repeater control with Paging functionality</td>
   </tr>
   <tr>
      <td>  <asp:label id="lblCurrentPage" runat="server"></asp:label></td>
   </tr>
   <tr>
      <td>  <asp:button id="cmdPrev" runat="server" text=" << "></asp:button>
          <asp:button id="cmdNext" runat="server" text=" >> "></asp:button></td>
   </tr>
</table>
<table border="1">
   <asp:repeater id="repeaterItems" runat="server">
      <itemtemplate>
         <tr>
            <td>  <b><%# DataBinder.Eval(Container.DataItem, "ProductTitle")%></b></td>
            <td>  <b><%# DataBinder.Eval(Container.DataItem, "ProductRef")%></b></td>
            <td>  <b><%# DataBinder.Eval(Container.DataItem, "Price")%></b></td>
         </tr>
      </itemtemplate>
   </asp:repeater>
</table>
 
 
 
public partial class results : System.Web.UI.Page
{
 
    public int CurrentPage
    {
        get
        {
            // look for current page in ViewState
            object o = this.ViewState["_CurrentPage"];
            if (o == null)
                return 0; // default page index of 0
            else
                return (int)o;
        }
 
        set
        {
            this.ViewState["_CurrentPage"] = value;
        }
    }
 
    protected void Page_Load(object sender, EventArgs e)
    {
        ItemsGet();
    }
 
    private void ItemsGet()
    {
 
        string phrase = Request.QueryString["phrase"];
        DataSet dsResults = DAOCartDB.SPs.SprocCartSelectSearchSimple(phrase).GetDataSet();
 
        // Populate the PagedDataSource control with the DataSet
        PagedDataSource pgResults = new PagedDataSource();
        pgResults.DataSource = dsResults.Tables[0].DefaultView;
 
        // Indicate that the data should be paged
        pgResults.AllowPaging = true;
 
        // Set the number of items you wish to display per page
        pgResults.PageSize = 1;
 
        // Set the PagedDataSource's current page
        pgResults.CurrentPageIndex = CurrentPage;
 
        lblCurrentPage.Text = "Page: " + (CurrentPage + 1).ToString() + " of " + pgResults.PageCount.ToString();
 
        // Disable Prev or Next buttons if necessary
        cmdPrev.Enabled = !pgResults.IsFirstPage;
        cmdNext.Enabled = !pgResults.IsLastPage;
 
        repeaterItems.DataSource = pgResults;
        repeaterItems.DataBind();
    }
 
    private void cmdPrev_Click(object sender, System.EventArgs e)
    {
        // Set viewstate variable to the previous page
        CurrentPage -= 1;
 
        // Reload control
        ItemsGet();
    }
 
    private void cmdNext_Click(object sender, System.EventArgs e)
    {
        // Set viewstate variable to the next page
        CurrentPage += 1;
 
        // Reload control
        ItemsGet();
    }    
}

Open in new window

0
Comment
Question by:rito1
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 3

Accepted Solution

by:
stu28bu earned 2000 total points
ID: 24790735
I see two possibilities:

1. There are no onClick events specified on the paging buttons.  Yes you defined the functions, but it doesn't look like you told the buttons to fire those functions.  If you look at the <asp:Buttons> in your sample they have an onClick setting pointing to the functions.
2. Is there a <form runat="server"> that is wrapping things?  You entire ASPX isn't posted so not sure if that is an issue or not.
0
 
LVL 1

Author Closing Comment

by:rito1
ID: 31600510
Hi stu28bu,

I totally missed the onClick hook!... this was the problem.

Many tanks,

Rit
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses

650 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question