【问题标题】:Paging in Repeater中继器中的分页
【发布时间】:2011-04-13 11:24:10
【问题描述】:

就像我们在 gridview 中有 pagesize 属性允许我们在页面之间来回切换一样,是不是我可以在转发器中合并相同的功能。

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

【问题讨论】:

    标签: c# asp.net gridview repeater


    【解决方案1】:

    查看http://plugins.jquery.com/project/paginateTable

    它基本上是使用 jQuery 对 html 表(您可以使用中继器构建)进行分页。

    它易于使用,具有自定义选项。 我已经用过了,效果很好。

    编辑

    您必须使用中继器构建您的表。我在下面提供了一个简单的示例:

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

    然后你的 javascript 应该在这个上调用 paginateTable 函数

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

    【讨论】:

    • 有趣...这意味着我必须将中继器绕在桌子上?
    • 奇怪我已经按照你说的做了一切......但是没有分页。所有项目都显示在同一页面上....不只是每页 2 个...并且下一个/上一个按钮不做任何事情。
    • 即使文章中给出的示例也不起作用...我也将 jquery 添加到我的 src 中
    • 插件你也加了吗?
    • 他们在devlegion.com/?page_id=15 有一个实时版本,这就是我在没有看到你的代码的情况下能做的所有事情
    【解决方案2】:

    Repeater and Control 提供了一种在 ASPX 页面上显示数据的快速灵活的方法。但它没有提供内置的分页功能。

    不过你可以做点什么...

    如果您想弄清楚,请参阅以下页面: http://www.codeproject.com/KB/webforms/Aspnet_Repeater_Control.aspx

    【讨论】:

      【解决方案3】:
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-12-28
      • 1970-01-01
      相关资源
      最近更新 更多