Live2D 看板娘 / Demo

c# Repeater 和 AspNetPager

1. 首先我们要引用一下AspNetPager.dll

 

2. 然后新建一个页面,在页面头部加上,这里很重要!!!

  <%@ Register Assembly="AspNetPager" Namespace="Wuqi.Webdiyer" TagPrefix="webdiyer" %>

 

3. 前台代码

  

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="KXL.Web.WebForm1" %>

<%@ Register Assembly="AspNetPager" Namespace="Wuqi.Webdiyer" TagPrefix="webdiyer" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <table>
            <tbody>
                <asp:Repeater ID="Repeater1" runat="server">
                    <ItemTemplate>
                        <tr>
                            <td class="am-hide-sm-only">
                                <%#Eval("ID")%>
                            </td>
                            <td class="am-hide-sm-only">
                                <%#Eval("UserName")%>
                            </td>
                            <td class="am-hide-sm-only">
                                <%#Eval("UserPhone")%>
                            </td>
                            <td class="am-hide-sm-only">
                                <%#Eval("Password")%>
                            </td>
                        </tr>
                    </ItemTemplate>
                </asp:Repeater>
            </tbody>
        </table><asp:Label ID="CountNumber" runat="server"></asp:Label>
        条记录
        <div class="am-fr">
            <webdiyer:AspNetPager ID="AspNetPager1" runat="server" FirstPageText="首页" HorizontalAlign="Center"
                AlwaysShow="True" PageSize="3" LastPageText="尾页" NextPageText="下一页" PrevPageText="上一页"
                OnPageChanged="AspNetPager1_PageChanged">
            </webdiyer:AspNetPager>
        </div>
    </div>
    </form>
</body>
</html>  

4. 后台代码

  

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace KXL.Web
{
    public partial class WebForm1 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

            if (!IsPostBack)
            {
                Bind();
            }
        }
        /// <summary>
        /// 绑定数据
        /// </summary>
        public void Bind()
        {
            int shang = AspNetPager1.PageSize * (AspNetPager1.CurrentPageIndex - 1) + 1;
            int xia = AspNetPager1.PageSize * AspNetPager1.CurrentPageIndex;
            string where = "1=1 ";
            AspNetPager1.RecordCount = new BLL.ss().GetRecordCount(where);
            this.CountNumber.Text = AspNetPager1.RecordCount.ToString();
            Repeater1.DataSource = new BLL.ss().GetListByPage(where, "", shang, xia);
            Repeater1.DataBind();
        }
        /// <summary>cuxiao
        /// 分页
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void AspNetPager1_PageChanged(object sender, EventArgs e)
        {
            Bind();
        }
    }
}

 

posted @ 2016-04-23 15:11  MChuang  阅读(342)  评论(0编辑  收藏  举报