如题,我用post传值方式搜索后里用AspNetPager来分页(两种模式:一种是AspNetPager不显示?page参数,另一种是Url分页即带参数?page=),我贴出我的代码:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
BindListData();
BindHot();
}
}
/// <summary>
/// 数据绑定--初始化
/// </summary>
private void BindListData()
{
DataSet ds1 = NewsBll.GetList("*", " Title Like '%" + Request.Form["txtKeyWord"].Trim()+ "%'", " ID DESC");//这里返回个DataSet ,问题:显示我第二页显示的时候Request.Form["txtKeyWord"]为空了,取的的数据条件就是like '%%'所有数据的第二页了,这是不显示?page参数的分页方式。aspnetpager带参数page的呢,又如何处理?请指教
AspNetPager1.RecordCount = ds1.Tables[0].Rows.Count;
Session["dvlist"] = ds1.Tables[0].DefaultView;
bindData();
}
/// <summary>
/// 数据绑定
/// </summary>
private void bindData()
{
if (ZsRequest.GetInt("page", 0) == 0)//ZsRequest类无须关注,我用来接收参数的一个封装类相当于 Request.QueryString("page")
{
CurrentPage = 1;
}
else
{
CurrentPage = Convert.ToInt32(ZsRequest.GetString("page"));
}
PagedDataSource pds = new PagedDataSource();
pds.AllowPaging = true;
pds.PageSize = AspNetPager1.PageSize;
pds.CurrentPageIndex = CurrentPage - 1;
pds.DataSource = (DataView)Session["dvlist"];
RPNewsList.DataSource = pds;
RPNewsList.DataBind();
}
protected void AspNetPager1_PageChanged(object sender, EventArgs e)
{
bindData();
}
我下面还有第二种写法,虽然不带page的分页功能实现了,但还是有个问题:当点击第二页时关键字的搜索我要在页面上显示,却显示不了,很显然是点击第二页时Request.Form["txtKeyWord"]为空了
const string vsKey = "searchCriteria"; //ViewState key
本文来自电脑杂谈,转载请注明本文网址:
https://www.pc-fly.com/a/jisuanjixue/article-34005-1.html
爱你
我国其实可以在南海举行实弹演习的
支持国产企业