ASP.NET 中真正的分页源代码

前台:<body>
    <form id="form1" runat="server">
    <div>
     <table border="1" width="1000">
                <tr>
                     <td>编号</td>
                     <td> 影片名称</td>
                     <td>主要演员</td>
                     <td>产地</td>
                     <td>上映时间</td>
                </tr>
                <%  foreach (var movie in movieList)
                    {%>
                        <tr>
                              <td><%=movie.Id%></td>
                              <td><%=movie.MovieName%></td>
                              <td><%=movie.Impersonator %></td>
                              <td><%=movie.Area %></td>
                              <td><%=movie.ModfiyDate %></td>
                       </tr>
                    <%}
                     %>
                      <tr>
          <td colspan="5"  style="text-align:center">
                 <a href="Split.aspx?current=1&&operate=first">首页</a>
                  <a href="Split.aspx?current=<%=currentPage %>&&operate=up">上一页</a>
                   <a href="Split.aspx?current=<%=currentPage %>&&operate=down">下一页</a>
                   <a href="Split.aspx?current=<%=pageCount %>&&operate=last">最后一页</a>
          </td>
        </tr>
          </table>
    </div>
    </form>
</body>

后台:public partial class Split : System.Web.UI.Page
    {
        public static int currentPage = 0; //当前页
        public IList<Movie> movieList = null; //每页显示的数据集合
        public int pageCount = 0;//一共要分的页数
        protected void Page_Load(object sender, EventArgs e)
        {

            int allCount = new MovieDal().getAllCount();
            //得到页数的值   20:每页显示的条数
            if (allCount %20 == 0)
            {
                pageCount = allCount / 20;
            }
            else
            {
                pageCount = allCount / 20 + 1;
            }
            string strCurrentPage = Request.QueryString["current"];
            //第一次加载进来  strCurrentPage=null; 首先给它一个默认值
            if (strCurrentPage ==null)
            {
                currentPage = 1;
            }
            else
            {
                currentPage = Convert.ToInt32(strCurrentPage);
            }
            //从前台获得要操作的类型
            string operate = Request.QueryString["operate"];
            if (operate=="first")
            {
                currentPage = 1;
            }
            else if (operate == "up")
            {
                if (currentPage>1)
                {
                    currentPage--;
                }
            }
            else if (operate == "down")
            {
                if (currentPage < pageCount)
                {
                    currentPage++;
                }
            }
            else if (operate == "last")
            {
                currentPage = pageCount;
            }
            else
            {
                currentPage = 1;
            }
            movieList = new MovieDal().getMoive(currentPage, 20);
          
        }
    }

转载于:https://www.cnblogs.com/PanderPeople/archive/2011/07/28/2119894.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值