我在DataGrid中删除数据时候,比如在删除第二页时,当第二页只剩一条记录,在删除时候就会出现“无效的 CurrentPageIndex 值。它必须大于等于 0 且小于 PageCount”,请问这问题怎么解决我是这么分页的
this.DataGrid1.CurrentPageIndex = e.NewPageIndex;
this.loadData();

解决方案 »

  1.   

    /// <summary>
    /// 删除
    /// </summary>
    /// <param name="source"></param>
    /// <param name="e"></param>
    private void DataGrid1_DeleteCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
    {
    // //用户编号
    // this.bus.S_id = int.Parse(e.Item.Cells[0].Text.Trim());
    //
    // //执行用户类的删除用户的方法
    // this.bus.del_Spli();
    //
    // //删除最后一页的最后一项时
    // if ( (this.DataGrid1.CurrentPageIndex == this.DataGrid1.PageCount - 1) && ( this.DataGrid1.Items.Count == 1) )
    // {
    // //如果还有其他页面时,则转到上一页
    // if ( this.DataGrid1.CurrentPageIndex - 1 > 1 )
    // {
    // this.DataGrid1.CurrentPageIndex = this.DataGrid1.CurrentPageIndex - 1;
    // }
    // else //只剩最后一页时
    // {
    // this.DataGrid1.CurrentPageIndex = 0;
    // }
    // }
    //
    // //数据绑定
    // this.bind_dg();