为什么我每次点下一页或最后一页时,当前页的显示都是显示上一次操作的页码,我的代码如下:
 protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
           if(Request["news_type"]!=null){
               string infor_type = Request["news_type"].ToString();
            SqlConnection mycon = SqlHelper.sqlcon();
            mycon.Open();
        
            string str = "select count(*) from 信息 where 信息类型='"+infor_type+"'";
            SqlCommand mycom = new SqlCommand(str, mycon);
            AspNetPager1.RecordCount = (int)mycom.ExecuteScalar();
            AspNetPager1.CustomInfoHTML = "记录总数:<font color='blue'><b>" + AspNetPager1.RecordCount.ToString() + "</b></font>";
            AspNetPager1.CustomInfoHTML += " 总页数:<font color='blue'><b>" + AspNetPager1.PageCount.ToString() + "</b></font>";
           Bind();
        }
        }
    }
    private void Bind()
    {
        if (Request["news_type"] != null)
        {
            string infor_type1 = Request["news_type"].ToString();
            SqlConnection mycon = SqlHelper.sqlcon();
            string str = "select top " + AspNetPager1.PageSize + " * from 信息 where 信息类型='" + infor_type1 + "'and 信息号 not in (select top " + AspNetPager1.PageSize * (AspNetPager1.CurrentPageIndex - 1) + " 信息号 from 信息 order by 信息号) order by 信息号";
            DataSet ds = SqlHelper.ExecuteDataset(SqlHelper.sqlcon(), CommandType.Text, str);            GridView1.DataSource = ds;
            GridView1.DataBind();
            mycon.Close();
        }
    }
    protected void AspNetPager1_PageChanging(object src, Wuqi.Webdiyer.PageChangingEventArgs e)
    {
        AspNetPager1.CurrentPageIndex = e.NewPageIndex;
        Bind();
    }
请问怎么回事,谢谢

解决方案 »

  1.   

    各位帮帮忙吧,我再说清楚一点,就是我一打开是第一页,点下一页还是第一页,再点下一页就是第二页了,其次就是第三页,以此类推,点最后一页也是显示上一次的页码,要到点下一次时才是最后一页的页码,不好意思,我上面的代码出了点问题,page_load应该是下面的代码:
        protected void Page_Load(object sender, EventArgs e)
        {
           
               
                string con = ConfigurationSettings.AppSettings["mc"];
                SqlConnection mycon = new SqlConnection(con);
                mycon.Open();
                string sql = "select count(*)  from 信息";
                SqlCommand mycom = new SqlCommand(sql, mycon);
                AspNetPager1.RecordCount = (int)mycom.ExecuteScalar();            AspNetPager1.CustomInfoHTML = "记录总数:<font color='blue'><b>" + AspNetPager1.RecordCount.ToString() + "</b></font>";
                AspNetPager1.CustomInfoHTML += " 总页数:<font color='blue'><b>" + AspNetPager1.PageCount.ToString() + "</b></font>";
                AspNetPager1.CustomInfoHTML += " 当前页:<font color='red'><b>" + AspNetPager1.CurrentPageIndex.ToString() + "</b></font>";
                Bind();
            
                    
        }
      

  2.   

    翻页那个事件弄错了吧
    AspNetPager1.CurrentPageIndex = e.NewPageIndex;
    Bind(); 
    这个应该写在AspNetPager1_PageChanged中的,而不是AspNetPager1_PageChanging
      

  3.   

     如楼上所言:
    protected void AspNetPager1_PageChanged(object src, Wuqi.Webdiyer.PageChangedEventArgs e)
        {        this.AspNetPager1.CurrentPageIndex = e.NewPageIndex;
            Bind();
        }
      

  4.   

    不对呀,这句话写在那里会报错,说“System.EventArgs”并不包含“NewPageIndex”的定义
      

  5.   

    我一直都是放在PageChanging 事件里,但是并没有遇到LZ所遇到的问题啊
      

  6.   

    我也不知道怎么回事呀,如果定在pagechanged事件的话,双击pagechanged事件会出现
    protected void AspNetPager1_PageChanged(object sender, EventArgs e)与4楼说的
    protected void AspNetPager1_PageChanged(object src, Wuqi.Webdiyer.PageChangedEventArgs e) 
    并不符,强行改也会报错:
    CS0234: 命名空间“Wuqi.Webdiyer”中不存在类型或命名空间名称“PageChangedEventArgs”(是缺少程序集引用吗?)   
      

  7.   

    支持 报错要查一下Wuqi.Webdiyer.PageChangedEventArgs e有没有设置对
      

  8.   


          this.AspNetPager1.CurrentPageIndex = e.NewPageIndex;
            Bind(); 放到pagechanged后,上面那一行去掉,只留下bind();
      

  9.   

    问题解决了,谢谢大家的帮忙,我做了下面的修改就行了
    protected void AspNetPager1_PageChanged(object sender, EventArgs e)
        {
            DataListDataBind();
            AspNetPager1.CustomInfoHTML = "记录总数:<font color='blue'><b>" + AspNetPager1.RecordCount.ToString() + "</b></font>";
            AspNetPager1.CustomInfoHTML += " 总页数:<font color='blue'><b>" + AspNetPager1.PageCount.ToString() + "</b></font>";
            AspNetPager1.CustomInfoHTML += " 当前页:<font color='red'><b>" + AspNetPager1.CurrentPageIndex.ToString() + "</b></font>";    }
    把这些也写到changed事件那就正常显示了,还想请教一下各位,为什么我的跳转到指定页的那个textbox不能输入数值的
      

  10.   

    来晚了1.AspNetPager1_PageChanged
    2.关键是你的Bind(),每次都是重新loading数据,自然每次都是第一页