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"]));
}

 

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

 

转载于:https://www.cnblogs.com/angels/p/4572050.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值