首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

AspNetPage中CurrentPageIndex值变化,但是也没显示始终为第一页。求解解决方案

2012-01-01 
AspNetPage中CurrentPageIndex值变化,但是也没显示始终为第一页。求解protected void Page_Load(object sen

AspNetPage中CurrentPageIndex值变化,但是也没显示始终为第一页。求解
protected void Page_Load(object sender, EventArgs e)
  {
  NewsBLL nbll = new NewsBLL();
  AspNetPager1.RecordCount = nbll.News_Web_GetNewsCountBYTNID(Convert.ToInt32(Request.QueryString["id"]));
  AspNetPager1.PageSize = 10;
  AspNetPager1.AlwaysShow = true;
  if (!string.IsNullOrEmpty(Request.QueryString["pg"]))
  {
  AspNetPager1.CurrentPageIndex = Convert.ToInt32(Request.QueryString["pg"]); 
  }
  if (!string.IsNullOrEmpty(Request.QueryString["id"]))
  {
  int id = Convert.ToInt32(Request.QueryString["id"]);
  if (id == 1) typeName = "最新动态"; else if (id == 2) typeName = "专属新闻"; else if (id == 3) typeName = "活动报道";
  if (!IsPostBack)
  {
  NewsModel nm = nbll.News_Web_SelectNewsInfoTop();
  New_Name.Text = nm.N_Name;
  New_Datetime.Text = nm.N_AuthorTime.ToString("yyyy-MM-dd");
  New_Menu.Text = nm.Tn_Name;
  comment_Count.Text = nm.Com_Count.ToString() + "条评论";

  JumpTo.HRef = "Content_" + nm.N_ID.ToString() + ".html";
  New_info.Text = nm.N_Describe.PadRight(50).Substring(0, 240);

  Pic_list.DataSource = nbll.News_Web_SelectNewPicBYNID(nm.N_ID);
  Pic_list.DataBind();
  }
  }
  indexPage.Text = AspNetPager1.CurrentPageIndex.ToString();
  }
  protected void AspNetPager1_PageChanging(object src, Wuqi.Webdiyer.PageChangingEventArgs e)
  {
  //AspNetPager1.CurrentPageIndex = e.NewPageIndex;
  int pages = 0;
  if (!string.IsNullOrEmpty(Request.QueryString["pg"]))
  {
  if (Convert.ToInt32(Request.QueryString["pg"]) == 0)
  pages = 1;
  else
  pages = Convert.ToInt32(Request.QueryString["pg"]);
  }
  else
  pages = 1;
  DataBind(pages - 1);
  }

  void DataBind(int pages)
  {
  NewsBLL nbll = new NewsBLL();
  New_List.DataSource = nbll.News_Web_SelectNewsInfoByTNID(Convert.ToInt32(Request.QueryString["id"]), pages);
  New_List.DataBind();
  }

使用的是url分页。分页可以,其他一切都好着呢。就是页面上的索引页的总是为第一个为选中的。郁闷了。
CurrentPageIndex的值也是正确的。不知道为什么了。

[解决办法]
//AspNetPager1.CurrentPageIndex = e.NewPageIndex;
你把这句注释了,可不是一直都是第一页吗?
[解决办法]

C# code
  protected void Page_Load(object sender, EventArgs e)    {        this.Pager.PageChanging += new Wuqi.Webdiyer.PageChangingEventHandler(Pager_PageChanging);      if (!IsPostBack)            {                this.Pager.PageSize = wlf.Common.Parameter.GridRows;                BindList();                            }} /// <summary>    /// 翻页    /// </summary>    /// <returns></returns>    private void Pager_PageChanging(object src, Wuqi.Webdiyer.PageChangingEventArgs e)    {        this.Pager.CurrentPageIndex = e.NewPageIndex;        BindList();    } /// <summary>    /// 绑定列表    /// </summary>    private void BindList()    {        string strWhere = GetWhere();        this.Pager.RecordCount = clsDAL.GetCountByWhere(strWhere);        DataTable dt = clsDAL.GetTableByWhere(strWhere, 10, this.Pager.CurrentPageIndex);        repList.DataSource = dt;        repList.DataBind();    } 

热点排行