效果图
前台代码
<%@ Register Assembly="AspNetPager" Namespace="Wuqi.Webdiyer" TagPrefix="webdiyer" %> <webdiyer:AspNetPager ID="AspNetPager2" runat="server" FirstPageText="首页" LastPageText="末页" NextPageText="下一页" NumericButtonCount="5" OnLoad="AspNetPager1_Load" OnPageChanged="AspNetPager1_PageChanged1" PageSize="2" PrevPageText="上一页" Font-Bold="False" Font-Size="13px" CssClass="badoo" UrlRewritePattern="" UrlPaging="true" CurrentPageButtonPosition="Center" PagingButtonSpacing="5px" ShowFirstLast="False" AlwaysShow="true"> </webdiyer:AspNetPager> <asp:Repeater ID="R1" runat="server"> <ItemTemplate> <div> <%#Eval("id") %>--<%#Eval("name") %></div> </ItemTemplate> </asp:Repeater> <webdiyer:AspNetPager ID="AspNetPager1" runat="server" FirstPageText="首页" LastPageText="末页" NextPageText="下一页" NumericButtonCount="5" OnLoad="AspNetPager1_Load" OnPageChanged="AspNetPager1_PageChanged1" PageSize="2" PrevPageText="上一页" Font-Bold="False" Font-Size="13px" CssClass="badoo" UrlRewritePattern="" UrlPaging="true" CurrentPageButtonPosition="Center" PagingButtonSpacing="5px" ShowFirstLast="False" AlwaysShow="true" ShowNavigationToolTip="True"> </webdiyer:AspNetPager> <asp:Label ID="lab_num" runat="server" Text=""></asp:Label>
后台代码
public void Bind() { int PageSize = 2; string sql = "select top " + PageSize + " id,name from name where id not in (select top " + PageSize * (PageNumber() - 1) + " id from name order by id desc ) order by id desc"; DataTable dt_5 = new DB.DB().RunSqlGetDataTable(sql); if (dt_5 != null && dt_5.Rows.Count > 0) { R1.DataSource = dt_5; R1.DataBind(); } } protected void AspNetPager1_PageChanged1(object sender, EventArgs e) { Bind(); } public int PageNumber() { int PageNumber = Request.QueryString["page"] != null ? Convert.ToInt32(Request.QueryString["page"].ToString()) : 1; return PageNumber; } protected void AspNetPager1_Load(object sender, EventArgs e) { string sql = "select count(id) as allnum from name "; DataTable dt_5 = new DB.DB().RunSqlGetDataTable(sql); if (dt_5 != null && dt_5.Rows.Count > 0) { int num = Convert.ToInt32(dt_5.Rows[0]["allnum"].ToString()); AspNetPager1.RecordCount = num; AspNetPager2.RecordCount = num; string html = ""; html += "记录总数:<font color=\"blue\"><b>" + AspNetPager1.RecordCount.ToString() + "</b></font> "; html += " 每页数:<font color=\"red\"><b>" + AspNetPager1.PageSize.ToString() + "</b></font> "; html += " 总页数:<font color=\"blue\"><b>" + AspNetPager1.PageCount.ToString() + "</b></font> "; html += " 当前页:<font color=\"red\"><b>" + AspNetPager1.CurrentPageIndex.ToString() + "</b></font> "; html += " 未显示页数:<font color=\"red\"><b>" + AspNetPager1.PagesRemain.ToString() + "</b></font> "; html += " 未显示记录数:<font color=\"red\"><b>" + AspNetPager1.RecordsRemain.ToString() + "</b></font>"; lab_num.Text = html; } }
css代码
/*分页*/ div.badoo { padding:20px 20px 20px 0px; text-align:left; } div.badoo a { border:1px solid #ededed; padding:10px 13px; color:#333333; border-radius:2px; margin-left:5px;} div.badoo a:hover {border:1px solid #ff5a00; color: #ff5a00; } div.badoo a:active {border:1px solid #ff5a00;} div.badoo span { border:1px solid #EDEDED; padding:10px 13px; color:#3399FF; font-weight:bold; background:#FAFAFA; border-radius:2px; margin-left:5px; color:#E8E8E8} div.badoo span.disabled { border:1px solid #EDEDED; padding:10px 13px; color:#333333; font-weight:100;}
时间: 2024-10-04 09:00:09