<ASP:DataGrid id="MyDataGrid" runat="server"
    OnPageIndexChanged="Page_Index"
........
C#:
...... 
protected void Page_Index(object sender,DataGridPageChangedEventArgs E) 
{
this.MyDataGrid.CurrentPageIndex=E.NewPageIndex; 
MyDataGrid.DataBind();}
注意,默认E是大写的。

解决方案 »

  1.   

    这是datagrid的问题了。
     如果你的datagrid 有30条数据,分页每页10条,那么就有1,2,3三页让你选。
       但是如果你点击3的时候,出现下面的情况就会有这种问题了。
      1.datagrid数据缘变化了,例如另外的客户端删掉11条数据阿,那么只有两页,你点3就出错了。
      2.datagird的绑定出现问题,这种比较常见,建议楼主看看page_load里面的东西,或者查查绑定datagrid的语句在那里,会不会出现空帮定的情况
      

  2.   

    TO:(gshope(gshope))
    那个e在函数中就是小写的,不是大写的。谢谢。TO:( camelials(陈祥))(shell(刚多) )用
    DataGrid1.CurrentPageIndex =e.NewPageIndex;
    DataGrid1.DataSource=this.dataset1;
    DataGrid1.DataBind();
    还是不行。
      

  3.   

    自己写一个绑定函数,如下:private void Bind()
    {
      this.DataGrid1.DataSource = dvGroup; // DataView dvGroup;
      if((dvGroup.Count - 1) / this.DataGrid1.PageSize < this.DataGrid1.CurrentPageIndex)
      this.DataGrid1.CurrentPageIndex = (dvGroup.Count - 1) / this.DataGrid1.PageSize;
      this.DataGrid1.DataBind();
    }然后在事件中如下调用
    DataGrid1.CurrentPageIndex =e.NewPageIndex;
    Bind();