vb.net 如何将数据分页器与中继器一起使用

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15019906/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-17 12:28:03  来源:igfitidea点击:

How to use datapager with Repeater

asp.netvb.netrepeaterdatapager

提问by Gericke

I have a Repeater control and inside my Repeater control I have many controls like gridview, detailsview and some other controls. But now my page become cluttered with controls as it repeats. What I want to achieve is to add the datapager to my page so that you can page through all the data in my controls. for example the first page would contain all items in my repeater with some data, second page all items with different data.

我有一个 Repeater 控件,在我的 Repeater 控件中,我有许多控件,如 gridview、detailsview 和其他一些控件。但是现在我的页面在重复时变得杂乱无章。我想要实现的是将数据分页器添加到我的页面,以便您可以分页浏览我的控件中的所有数据。例如,第一页将包含我的转发器中的所有项目和一些数据,第二页将包含具有不同数据的所有项目。

Here is my Repeater control:

这是我的中继器控件:

<asp:Repeater ID="Repeater1" runat="server"  DataSourceID="SchemeDataSource1">
 <ItemTemplate>
    <table style="border: thin solid #000000"; width: "100%" >
      <tr>
        <td>PRENO
           <asp:Label ID="lblPreno" runat="server" Text='<%# Bind("PRENR") %>'></asp:Label>
            MONTHLY PREMIUM
            <asp:Label ID="lblPrem" runat="server" Text='<%# Bind("PREMIUM") %>'></asp:Label>
        <br />
        </td>
        <td align="right">
         <asp:LinkButton ID="lnkPre" runat="server" 
         ToolTip="Copy Premium To New Scheme" Font-Bold="True" Font-Size="Larger" Visible="true">>></asp:LinkButton>
        </td>
       </tr>

       <tr>
        <td>Relation: [
         <asp:Label ID="lblRel" runat="server" Text='<%# Bind("RELATION") %>'></asp:Label>
        ] UWCODE: [
        <asp:Label ID="lblUw" runat="server" Text='<%# Bind("UWFEECODE") %>'></asp:Label>
       ][
       <asp:Label ID="lblUwDescription" runat="server" Text='<%# Bind("DESCRIPTION") %>'></asp:Label>
       ]
       <br />
       </td>
       </tr>                                                    
       </table>

       <table>
         <tr align="left" valign="top">
          <td align="left">
           <asp:DetailsView ID="dvEarner" runat="server" HeaderText="NO EARNER"
           EmptyDataText="No Results To Display" HeaderStyle-BorderColor="Black"
           HeaderStyle-BorderStyle="Solid" HeaderStyle-BorderWidth="1px"
           BackColor="#DEBA84" BorderColor="#DEBA84" BorderStyle="None"
           BorderWidth="1px" CellPadding="3" CellSpacing="2" EnableViewState="False">
           <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
           <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
           <PagerStyle ForeColor="#8C4510" HorizontalAlign="Center"/>
           <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
           </asp:DetailsView>
                                </td>
                                <td align="left">
                                    <asp:DetailsView ID="dvJVName" runat="server" HeaderText="JV NAME"
                                        HeaderStyle-BorderColor="Black" HeaderStyle-BorderStyle="Solid" HeaderStyle-BorderWidth="1px"
                                        EmptyDataText="JV NAME"
                                        AlternatingRowStyle-BorderStyle="Solid" AlternatingRowStyle-BorderWidth="1px"
                                        BackColor="#DEBA84" BorderColor="#DEBA84" BorderStyle="None"
                                        BorderWidth="1px" CellPadding="3" CellSpacing="2">
                                        <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
                                        <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
                                        <PagerStyle ForeColor="#8C4510" HorizontalAlign="Center" />
                                        <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
                                        <EmptyDataRowStyle BackColor="#5D7B9D" ForeColor="White" Font-Bold="true" />
                                    </asp:DetailsView>
                                </td>
                                <td align="left">
                                    <asp:DetailsView ID="DetailsView1" runat="server" HeaderText="%"
                                        HeaderStyle-BorderColor="Black" HeaderStyle-BorderStyle="Solid" HeaderStyle-BorderWidth="1px"
                                        EmptyDataText="%"
                                        AlternatingRowStyle-BorderStyle="Solid" AlternatingRowStyle-BorderWidth="1px"
                                        BackColor="#DEBA84" BorderColor="#DEBA84" BorderStyle="None"
                                        BorderWidth="1px" CellPadding="3" CellSpacing="2">
                                        <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
                                        <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
                                        <PagerStyle ForeColor="#8C4510" HorizontalAlign="Center" />
                                        <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
                                        <EditRowStyle BackColor="#738A9C" Font-Bold="True" ForeColor="White" />
                                        <EmptyDataRowStyle BackColor="#5D7B9D" ForeColor="White" Font-Bold="true" />
                                    </asp:DetailsView>
                                </td>
                                <td align="left">
                                    <asp:DetailsView ID="dvProduct" runat="server" HeaderText="PRODUCT DETAILS"
                                        HeaderStyle-BorderColor="Black" HeaderStyle-BorderStyle="Solid" HeaderStyle-BorderWidth="1px"
                                        EmptyDataText="No Results To Display"
                                        AlternatingRowStyle-BorderStyle="Solid" AlternatingRowStyle-BorderWidth="1px"
                                        BackColor="#DEBA84" BorderColor="#DEBA84" BorderStyle="None"
                                        BorderWidth="1px" CellPadding="3" CellSpacing="2">
                                        <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
                                        <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
                                        <PagerStyle ForeColor="#8C4510" HorizontalAlign="Center" />
                                        <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
                                    </asp:DetailsView>
                                </td>
                                <td align="left">
                                    <asp:DetailsView ID="dvFeeDetails" runat="server" HeaderText="ADDITIONAL FEE DETAILS"
                                        HeaderStyle-BorderColor="Black" HeaderStyle-BorderStyle="Solid" HeaderStyle-BorderWidth="1px"
                                        EmptyDataText="No Results To Display"
                                        AlternatingRowStyle-BorderStyle="Solid" AlternatingRowStyle-BorderWidth="1px"
                                        BackColor="#DEBA84" BorderColor="#DEBA84" BorderStyle="None"
                                        BorderWidth="1px" CellPadding="3" CellSpacing="2">
                                        <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
                                        <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
                                        <PagerStyle ForeColor="#8C4510" HorizontalAlign="Center" />
                                        <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
                                    </asp:DetailsView>
                                    <br />
                                </td>
                            </tr>
                        </table>

             <table>
                             <tr>
                                <td>
                                    <strong><u>UNDERWRITER DETAILS:</u></strong> 
                                    <asp:GridView ID="grdUWDetails" runat="server" ForeColor="#333333" CellPadding="4" AutoGenerateSelectButton="False">
                                        <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
                                        <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
                                        <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
                                        <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
                                        <EmptyDataTemplate>No results to display.</EmptyDataTemplate>
                                    </asp:GridView>
                                    <br />
                                    <hr />
                                </td>
                            </tr>
                        </table>
        </ItemTemplate>
    </asp:Repeater>

To bind my controls in my repeater:

在我的中继器中绑定我的控件:

Private Sub Repeater1_ItemDataBound(ByVal sender As Object, ByVal e As     System.Web.UI.WebControls.RepeaterItemEventArgs) Handles Repeater1.ItemDataBound
If e.Item.ItemType = ListItemType.Item OrElse e.Item.ItemType = ListItemType.AlternatingItem Then
  Dim strPreno As String = DirectCast(e.Item.FindControl("lblPreno"), Label).Text

  Dim dv As DetailsView = DirectCast(e.Item.FindControl("dvEarner"), DetailsView)
  dv.DataSource = fnLoadPremiums(strPreno)
  dv.DataBind()

  Dim dv1 As DetailsView = DirectCast(e.Item.FindControl("dvProduct"), DetailsView)
  dv1.DataSource = fnLoadProduct(strPreno)
  dv1.DataBind()

  Dim dv2 As DetailsView = DirectCast(e.Item.FindControl("dvFeeDetails"), DetailsView)
  dv2.DataSource = fnLoadFeeDetails(strPreno)
  dv2.DataBind()

  Dim grd As GridView = DirectCast(e.Item.FindControl("grdUWDetails"), GridView)

  grd.DataSource = fnLoadGrid(strPreno)
  grd.DataBind()
End If
End Sub

Or if you have any ideas how to achieve this it would be much appreciated.

或者,如果您有任何想法如何实现这一点,将不胜感激。

I have used the datapager but I got this error: Control 'Repeater1' does not implement IPageableItemContainer. Then I did some researched about this the datapager only works with listview. So now I want the same method as the datapager but nor sure how to achieve this. Any Ideas?

我使用了数据分页器,但出现此错误:控件“Repeater1”未实现 IPageableItemContainer。然后我对此进行了一些研究,数据分页器仅适用于列表视图。所以现在我想要与 datapager 相同的方法,但不确定如何实现这一点。有任何想法吗?

采纳答案by Gericke

solved the issue is going to use <ajaxToolkit:Accordion></ajaxToolkit:Accordion>This way I can uses panes to hide repeated controls.

解决了这个问题将使用<ajaxToolkit:Accordion></ajaxToolkit:Accordion>这种方式我可以使用窗格来隐藏重复的控件。

回答by scripni

You could extend the Repeaterto implement IPageableItemContainer, here's a link to an implementation on codeproject.

您可以扩展Repeater以实现IPageableItemContainer,这里是codeproject 上实现的链接。

回答by RedDevil79

You can use PagedDatasource to bind the repeater, check this link:

您可以使用 PagedDatasource 来绑定转发器,请查看此链接:

http://www.dotnetfunda.com/articles/article980-paging-with-repeater-control.aspx

http://www.dotnetfunda.com/articles/article980-paging-with-repeater-control.aspx