0

I have a Repeater inside a datapager to display some of the page numbers, I'm using a templated pager field because there is other data inside there as well, and since I want to be able to re-use this, I have abstracted it out to a user control which is embedded in the data pager.

Here is the pager with the user control

<asp:DataPager ID="MessagesDataPager" SkinID="AdminCorrespondenceDataPager" PagedControlID="MessagesListView" runat="server">
    <Fields>
        <asp:TemplatePagerField OnPagerCommand="Pager_OnPagerCommand">
            <PagerTemplate>
                <uc:ListViewPager Id="Pager" runat="server" />
            </PagerTemplate>
        </asp:TemplatePagerField>
    </Fields>
</asp:DataPager>

Here is the user control

<p class="pag">
    <span class="pagerSummaryPages"><asp:Literal ID="SummaryLiteral" runat="server" /></span>
    <asp:LinkButton ID="PreviousPageButton" runat="server" Text="&lt Previous" OnCommand="ChangePageCommand" CommandArgument="-1" />
    <span>
        <asp:Repeater ID="PageLinksRepeater" OnItemDataBound="PageLinksRepeater_OnItemDataBound" runat="server">
            <ItemTemplate>
                <asp:LinkButton ID="PageLink" CssClass="pageLink" runat="server" OnCommand="ChangePageCommand" />
            </ItemTemplate>
        </asp:Repeater>
    </span>
    <asp:LinkButton  ID="NextPageButton" runat="server" Text="Next &gt;" OnCommand="ChangePageCommand" CommandArgument="1" />
</p>

So the link buttons that are not in the repeater work correct and the template pager field receives the PagerCommand event, but when the link buttons inside the repeater are clicked they fire a postback and their own command event, but the PagerCommand event on the TemplatedPagerField is never fired.

The whole point of this is a re-useable control that generates paging values similar to 25-50 of 167 < Previous 2 3 4 Next >

4

1 回答 1

0

永远无法让它正常工作,而是用占位符替换中继器并动态添加链接按钮,在大多数情况下,这工作得很好。所以用户控件变成了

<p class="pag">
    <span class="pagerSummaryPages"><asp:Literal ID="SummaryLiteral" runat="server" /></span>
    <asp:LinkButton ID="PreviousPageButton" runat="server" Text="&lt Previous" OnCommand="ChangePageCommand" CommandArgument="-1" />
    <span>
        <asp:PlaceHolder ID="LinksPlaceHolder" runat="server" />
    </span>
    <asp:LinkButton  ID="NextPageButton" runat="server" Text="Next &gt;" OnCommand="ChangePageCommand" CommandArgument="1" />
</p>

并在 OnInit 函数中添加了我的动态链接按钮。

于 2011-07-12T01:21:15.267 回答