asp.net中让Repeater和GridView支持DataPager分页(2)


<WYJ:DataPagerRepeater runat="server" PersistentDataSource="true">
<ItemTemplate>
<div>
<div>
<div>
<%# ((GeekStudio.ORM.Model.Leaveword)Container.DataItem).Posttime.ToString("HH:mm") %></div>
<div>
<%# ((GeekStudio.ORM.Model.Leaveword)Container.DataItem).Posttime.ToString("dd") %>
</div>
<div>
<%# ((GeekStudio.ORM.Model.Leaveword)Container.DataItem).Posttime.ToString("MMM", new CultureInfo("en-US")).ToUpper() %><%# ((GeekStudio.ORM.Model.Leaveword)Container.DataItem).Posttime.ToString(" yyyy") %></div>
</div>
<div>
<h2>
<a
name="<%# GeekStudio.Common.IdEncryptor.EncodeId(((GeekStudio.ORM.Model.Leaveword)Container.DataItem).Id) %>">
<%# ((GeekStudio.ORM.Model.Leaveword)Container.DataItem).Username %></a></h2>
<div>
<%# ((GeekStudio.ORM.Model.Leaveword)Container.DataItem).Content %>
</div>
</div>
</div>
</ItemTemplate>
</WYJ:DataPagerRepeater>


之后添加.NET自带的DataPager,并自定义一些分页样式

复制代码 代码如下:


<div>
<div>
共<%=Math.Ceiling((double)DataPager1.TotalRowCount / DataPager1.PageSize)%>页,<%=DataPager1.TotalRowCount%>条记录,每页显示
<asp:LinkButton CssClass="currentpagesize" runat="server">10</asp:LinkButton>
<asp:LinkButton runat="server">20</asp:LinkButton>
<asp:LinkButton runat="server">30</asp:LinkButton>
</div>
<asp:DataPager PagedControlID="rptLeaveword" runat="server">
<Fields>
<asp:NextPreviousPagerField ShowFirstPageButton="True" ShowNextPageButton="False"
ShowPreviousPageButton="False" FirstPageText="首页" />
<asp:NextPreviousPagerField ShowNextPageButton="False" ButtonType="Image" PreviousPageImageUrl="~/Images/icons/pagerprevious.png" />
<asp:NumericPagerField CurrentPageLabelCssClass="current" />
<asp:NextPreviousPagerField ShowPreviousPageButton="False" ButtonType="Image" NextPageImageUrl="~/Images/icons/pagernext.png" />
<asp:NextPreviousPagerField ShowLastPageButton="True" ShowNextPageButton="False"
ShowPreviousPageButton="False" LastPageText="尾页" />
</Fields>
</asp:DataPager>
</div>


后台代码:
分页部分不需要代码。下面发的代码是切换每页显示数量的:

复制代码 代码如下:

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wjdpss.html