简体   繁体   中英

how to have both page numbers and and next & previous buttons in custom pager in asp.net grid view?

What I want is a pagination structure of this type.

在此处输入图像描述

I am able to display the previous and next buttons using the code below and they are functional too.

    <PagerTemplate>

          <asp:LinkButton CommandName="Page" CommandArgument="Prev" ID="LinkButton2" runat="server" Style="color: Black">
                <asp:Image ID="Image2" runat="server" ImageUrl="~/Images/videos_page_arrow_previous.gif"/>
          </asp:LinkButton>

          [Records <%= gridviewVideos.PageIndex * gridviewVideos.PageSize%>-<%= gridviewVideos.PageIndex * gridviewVideos.PageSize + gridviewVideos.PageSize - 1%>]

          <asp:LinkButton CommandName="Page" CommandArgument="Next" ID="LinkButton3" runat="server" Style="color: Black">
                <asp:Image ID="Image1" runat="server" ImageUrl="~/Images/videos_page_arrow_next.gif"/>
          </asp:LinkButton>  

    </PagerTemplate>

But I am not sure how to achieve in getting the page numbers in between them. Each page of mine contains 5 rows, if I use a repeater control to do that, then how?

For these kind of scenarios you should ideally wanna use asp:ListView coupled with asp:DataPager . But if you are persisting with a asp:GridView you should extend it to use asp:DataPager

I have been using Matt Berseth's Using a DataPager with the GridView Control - Implementing IPageableItemContainer . But the demo / download site is down. So you could download the same from GridView with DataPager in ASP.NET 3.5 which I believe is more or less trhe same code.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM