代码应该是没问题的,我也断点测试过了,CurrentPageIndex赋值过后还是1,有人遇到过这种情况吗?

解决方案 »

  1.   

    那是因为数据没有保存       private int currentPageIndex
        {
            get
            {
                if (ViewState["currentPageIndex"] != null)
                {
                    return Convert.ToInt32(ViewState["currentPageIndex"].ToString());
                }
                else
                {
                    return 1;
                }
            }
            set
            {
                ViewState["currentPageIndex"] = value;
            }
        }
      

  2.   

    这个需要赋值吗?这个值是控件动态获得的吧?你绑定数据是否没放在isPostBack里面?
      

  3.   


    public void BindGridView(int pageIndex)
        {
            
           AspNetPager1.CurrentPageIndex = pageIndex;
           Label12.Text = AspNetPager1.CurrentPageIndex.ToString();//测试赋值               
           OleDbDataAdapter da;
            Conn().Open();
            string choiceString;
            AspNetPager1.PageSize = 50;
            AspNetPager1.RecordCount = Int32.Parse(GetAllCount().ToString());
            choiceString = MakeString(TextBox1, TextBox2, TextBox3, TextBox4,
             TextBox5,TextBox6, TextBox7, TextBox8);
            da = new OleDbDataAdapter(choiceString, Conn());
            DataSet ds = new DataSet();
             da.Fill(ds, (pageIndex- 1) * AspNetPager1.PageSize, AspNetPager1.PageSize, "总表");
            GridView1.DataSource=ds.Tables[0];
            GridView1.DataBind();
            AspNetPager1.CustomInfoHTML = "记录总数:<b>" + AspNetPager1.RecordCount.ToString() + "</b>";
            AspNetPager1.CustomInfoHTML += " 总页数:<b>" + AspNetPager1.PageCount.ToString() + "</b>";
            AspNetPager1.CustomInfoHTML += " 当前页:<font color=\"red\"><b>" + AspNetPager1.CurrentPageIndex.ToString() + "</b></font>";
        }
    我在Page_Load(object sender, EventArgs e)里面写
    if (!IsPostBack)
            {
                      BindGridView(2);
                  }Label12.Text 的值都为1!
      

  4.   

    我主要是想实现功能是,我在主页面选择第n页,通过按钮弹出窗口,弹出窗口关闭后,刷新主页面,但是显示的页数还是第n页,所以需要对CurrentPageIndex赋值,大家有什么好方法吗?
      

  5.   


    public void BindGridView(int pageIndex)
        {
            AspNetPager1.RecordCount = Int32.Parse(GetAllCount().ToString());//这句放头上
                    
           OleDbDataAdapter da;
            Conn().Open();
            string choiceString;
            AspNetPager1.PageSize = 50;
            
            choiceString = MakeString(TextBox1, TextBox2, TextBox3, TextBox4,
             TextBox5,TextBox6, TextBox7, TextBox8);
            da = new OleDbDataAdapter(choiceString, Conn());
            DataSet ds = new DataSet();
             da.Fill(ds, (pageIndex- 1) * AspNetPager1.PageSize, AspNetPager1.PageSize, "总表");
            GridView1.DataSource=ds.Tables[0];
            GridView1.DataBind();
            AspNetPager1.CustomInfoHTML = "记录总数:<b>" + AspNetPager1.RecordCount.ToString() + "</b>";
            AspNetPager1.CustomInfoHTML += " 总页数:<b>" + AspNetPager1.PageCount.ToString() + "</b>";
            AspNetPager1.CustomInfoHTML += " 当前页:<font color=\"red\"><b>" + AspNetPager1.CurrentPageIndex.ToString() + "</b></font>";
    AspNetPager1.CurrentPageIndex = pageIndex;
           Label12.Text = AspNetPager1.CurrentPageIndex.ToString();//测试赋值      
        }
      

  6.   

     da.Fill(ds, (pageIndex- 1) * AspNetPager1.PageSize,pageIndex* AspNetPager1.PageSize, "总表");
    还有如果本身我总共的PAGE只有一页怎么办?你设个2有什么用?
      

  7.   

    我明白了,你PageIndex每次点第n页后,页面刷新,PageIndex都初始化了=1
      

  8.   

    你父页面SUBMIT一次也可以保持在同一页面啊。
      

  9.   

    这里是我写错了,之前我在这里做了调试,没改回来。pageIndex改为AspNetPager1.CurrentPageIndex
      

  10.   

    你可以每次点下一页在AspnetPageing事件里重新绑定,这句加个判断
    if(Session["flag"]==null)
    {
       pageindex=1;
    Session["flag"]=1;
    }
    else
      pageindex=AspNetPager1.CurrentPageIndex;
      

  11.   

    aspnetpage有个bug就是如果走Url方式,就每次都会经过Page_load,所有每次都PostBack=false
      

  12.   

    我在函数里,把pageIndex赋值给AspNetPager1.CurrentPageIndex之后,pageIndex就没用了,只是充当一个零时变量。之前是我写错了,不好意思
      

  13.   

    但问题是每次都走PageLoad里,pageindex初始值如果为1的化,每次走到绑定数据方法里,AspNetPager1.CurrentPageIndex都=1了
      

  14.   


    window.opener.refresh();
    parent page:
    function refresh()
    {
     document.getElementById('<%=hidValue.ClientID%>')='refresh';
     document.forms[0].submit();
    }cs
    if(!Page.isPostBack)
    {
     //...
    }
    else
    {
     if(hidValue.Value=="refresh")
     {
     BindData();
    hidValue.Value="";
    }
    }
      

  15.   

    在PageLoad里面,我没用到pageindex这个变量,我是通过别的页面传过来的值,然后直接调用BindGridView()这个函数的,主要问题就是在BindGridView()里AspNetPager1.CurrentPageIndex
    赋非“1”值之后还是为1,我郁闷啊。
      

  16.   

    page_load里面我是这样写的protected void Page_Load(object sender, EventArgs e)
        {
            
            if (!IsPostBack)
            {
                if (Session["pageIndex"] == null)
                {
                    BindGridView(1);
                 }
                if(Session["pageIndex"]!=null)
                {
                    string pageIndex = Session["pageIndex"].ToString();
                    int index = Int32.Parse(pageIndex);   
                    BindGridView(index);
                    Session.Remove("pageIndex");
                }
            }
        }
      

  17.   

    各位,我解决了,需要先给AspNetPager1.RecordCount赋值,才能给AspNetPager1.CurrentPageIndex赋值,不知道这算不算一个bug。