zoukankan      html  css  js  c++  java
  • MVC中,加入的一个aspx页面用到AspNetPager控件处理办法

    今天项目遇到了如题所示的问题,按照官方的案例介绍做分页,简直要奔溃了,

    使用URL重写,但是page总是1,根本不跳,

    不使用URL重写,又出现,第一页是 http://aa.com/view_aspx/pagetest.aspx?page=1,点击第二页就变成http://aa.com/pagetest.aspx?page=2 这样路径不对

    最近解决办法

    首先是页面控件部分,特别注意红色部分,那个page一定要用page ,用别的没有用的

    <webdiyer:AspNetPager ID="AspNetPager1" runat="server" UrlPaging="True" UrlPageSizeName="page" PageIndexBoxType="DropDownList"
    HorizontalAlign="left" PageSize="5"
    OnPageChanged="AspNetPager1_PageChanged" CssClass="pages"
    CurrentPageButtonClass="cpb" FirstPageText="首页" LastPageText="最后一页"
    NextPageText="下一页" PrevPageText="上一页" EnableUrlRewriting="true" UrlRewritePattern="/View_Aspx/EvalInfoList.aspx?page={0}">

    然后后台里面:ViewState["currentPageId"] 保存他的页码值

    if (Request.QueryString["page"] != null && !string.IsNullOrEmpty(Request.QueryString["page"].ToString()))
    {
    int currentPageId = Convert.ToInt32(Request.QueryString["page"].ToString());
    ViewState["currentPageId"] = currentPageId;
    }
    else
    {
    ViewState["currentPageId"] = 1;
    }

    AspNetPager1.CurrentPageIndex = Convert.ToInt32(ViewState["currentPageId"]);
    AspNetPager1.RecordCount = evalservice.GetEvaltionListCount(sitelangId);

    if (!IsPostBack)
    {
    BindData(1);
    }

    //分页事件里面这样写:

    protected void AspNetPager1_PageChanged(object src, EventArgs e)
    {
    BindData(Convert.ToInt32(ViewState["currentPageId"]));
    }

    目前来讲测试过几页没有问题的

  • 相关阅读:
    JAVA常见面试题之Forward和Redirect的区别
    springMVC学习笔记(二)-----注解和非注解入门小程序
    springMVC学习笔记(一)-----springMVC原理
    C语言关键字
    JAVA HASHMAP 如何用
    java中HashMap详解
    java中dao层和service层的区别是什么?
    到底DAO是什么?为什么要有它的存在?
    Ubuntu命令基础
    使用VMWare12.0安装Ubuntu系统
  • 原文地址:https://www.cnblogs.com/angels/p/4572050.html
Copyright © 2011-2022 走看看