Paging in Repeater

user478636 picture user478636 · Apr 13, 2011 · Viewed 12.3k times · Source

Just like we have pagesize property in gridview that allows us to switch back and forth between pages, isn't there anyway i can incorporate the same functionality in a repeater.

<table id="myTable">
    <tbody>
        <asp:Repeater ID="Repeater1" runat="server"
            onitemcommand="addItem_OnClick" DataMember="DefaultView">
            <ItemTemplate>
            <tr>
                <td>

                <div class="product">
                <table border="0" cellpadding="0" cellspacing="0" width="100%">
                    <tr valign="top">
                        <td width="105"><asp:HyperLink ID="HLSysDet" runat="server"
                            NavigateUrl='<%# "/Product.aspx?productId=" + Eval("ProductDescriptionId") %>'>
                            <asp:Image ID="Image1" runat="server" width="85" height="85"
                                ImageUrl='<%# Eval("Thumbnail")%>' border="0" />
                        </asp:HyperLink></td>
                        <td><ItemTemplate><a
                            href='<%# "/Product.aspx?productId=" + Eval("ProductDescriptionId") %>'>
                        '<%# Eval("ProductName")%>'</a> </ItemTemplate></b><br />
                        <br />

                        Manufacturer: <%# Eval("Manufacturer")%><br />
                        <br />
                        <b>Rs <%# Eval("UnitPrice")%>
                        </b><br />
                        <br />
                        Weight: <%# Eval("Weight")%> Kg<br />

                        </td>
                        <td width="20"></td>
                        <td valign="bottom" width="130">
                        <%# Eval("Quantity")%>+ in stock<br />


                        <asp:TextBox ID="_qty" runat="server" CssClass="textbox"
                            MaxLength="2" Text="1" Width="30"
                            Visible='<%# showBtn(Eval("Quantity")) %>' /> <asp:RangeValidator
                            ID="RangeValidator1" runat="server" ControlToValidate="_qty"
                            ErrorMessage="*" ForeColor="Red" MaximumValue="50"
                            MinimumValue="1"></asp:RangeValidator>
                        <div class="buttons"><span id="Span1" class="mandatory"
                            runat="server" visible='<%# isQty(Eval("Quantity")) %>'>
                        Sorry, this item is out of stock</span></div>




                        <div class="buttons"><br />
                        <asp:LinkButton ID="CommandButton" runat="server"
                            Text='Add to Cart' CssClass="positive" CommandName="Add"
                            CommandArgument='<%# Eval("ProductDescriptionId") %>'
                            Visible='<%# showBtn(Eval("Quantity")) %>' />
                        </div>




                        </td>


                    </tr>
                    </div>
                </table>
                </div>
                </td>
            </tr>
            </ItemTemplate>
        </asp:Repeater>
    </tbody>
</table>
<div class='pager'><a href='#' alt='Previous' class='prevPage'>Prev</a>
<span class='currentPage'></span> of <span class='totalPages'></span> <a
    href='#' alt='Next' class='nextPage'>Next</a></div>

Answer

koenmetsu picture koenmetsu · Apr 13, 2011

Check out http://plugins.jquery.com/project/paginateTable.

It's basically pagination on a html table ( which you can build using a repeater ) using jQuery.

It's easy to use, has customization options. I used it already, worked just fine.

EDIT

You'd have to build your table with a repeater. I've provided a quick example below:

<table id="myTable">
  <tbody>
      <asp:Repeater ...>
          <ItemTemplate>
              <tr><td><%# Eval('Description') %></td></tr>
          </ItemTemplate>
      </asp:Repeater>
   <tbody>
</table>
<div class='pager'>
   <a href='#' alt='Previous' class='prevPage'>Prev</a>
   <span class='currentPage'></span> of <span class='totalPages'></span>
   <a href='#' alt='Next' class='nextPage'>Next</a>
</div>

Your javascript should then call the paginateTable function on this

<script>
    $(document).ready(function () {
        $('#myTable').paginateTable({ rowsPerPage: 2 });
    });
</script>