paging information (like CurrentPageIndex) is saved in the viewstate, consider to save them in the session variable or hidden control

解决方案 »

  1.   

    consider to save them in the session variable or hidden control
    我也这么想过,可是我读取不到页码,怎么保存呢?我可以首先设置页码为0,但是跟着点了第5页,我无法取得5,怎么在session里设置为5呢??
      

  2.   

    http://dev.csdn.net/article/29/29802.shtm
      

  3.   

    CMIC(大象) 
    这边文章也没有说enableviewstate设置为false后怎么读取页码啊
      

  4.   

    <asp:DataGrid id="DataGrid1" runat="server" AllowPaging="True" PageSize="3" EnableViewState="False">
    <PagerStyle Mode="NumericPages"></PagerStyle>
    </asp:DataGrid>
    *.cs:
    private void Page_Load(object sender, System.EventArgs e)
    {
        if (!IsPostBack)
        {
    DataGrid1.DataSource = CreateDataSource();
    DataGrid1.DataBind();
        }
    }
    ...
    private void DataGrid1_PageIndexChanged(object source, System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
    {
    DataGrid1.CurrentPageIndex = e.NewPageIndex;
    DataGrid1.DataSource = CreateDataSource();
    DataGrid1.DataBind();
    }
    把你的代码贴一下
      

  5.   

    acewang(龍芯*Inside!) 
    基本上我的代码差不多就那样,不过我是在<@ Page EnableViewState="false" %>这里设置了,DataGrid那里就用默认的(应该是true)
    但是很奇怪,我点击分页的时候,并没有调用DataGrid1_PageIndexChanged
    我在DataGrid1.CurrentPageIndex = e.NewPageIndex;这里设了断点的,但没有在这里停止
      

  6.   

    因为你把整个页面的ViewState禁用了,所以事件根本无法激发
      

  7.   

    是啊,后来我重写了DataGrid的OnLoad事件,调用PageIndexChanged事件,但是我无法取得页码,否则可以通过这种方式来实现
      

  8.   

    去除DataGrid中无用的ViewState数据的方法
    http://dev.csdn.net/develop/article/23/23670.shtm
      

  9.   

    //重载该方法为DataGrid瘦身
    protected override object SaveViewState() 

    this.Controls[0].EnableViewState=false;
    return base.SaveViewState();