• DataGrid中删除后出现无效的CurrentPageIndex值


    无效的 CurrentPageIndex 值。它必须大于等于 0 且小于 PageCount。


    说明:
    执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。

    异常详细信息: System.Web.HttpException: 无效的 CurrentPageIndex 值。它必须大于等于 0 且小于 PageCount。

    源错误:

    行 174: grdClass.DataSource = dt;
    行 175: grdClass.DataBind();
    行 176: }

    这种情况是在删除当前分页的最后一条记录后出现的,以前没有发现,到网上找到了解决方法,但是不是很理想。
    后来请教了高手,主要问题是删除后重新DataBind时没有记录,CurrentPageIndex的发生异常。
    解决方法就是在DataBind时候用try;catch,刚学写程序还没用过try,别笑我,我也不是很懂,意思就是DataBind出错时,执行catch,在catch中加上this.DataGrid.CurrentPageIndex-=1,然后再DataBind();

    private void Bind()
    {
        prjFactory.LeaveWord lw 
    = new prjFactory.LeaveWord();
        prjSystem.Qualifier qlf 
    = new prjSystem.Qualifier();
        DataTable ds 
    = lw.queryAsDataTable(qlf);
        
    this.DataGrid.DataSource = ds;
        
    try
        
    {
        
    this.DataGrid.DataBind();
        }

        
    catch//(Exception e)
        {                this.DataGrid.CurrentPageIndex-=1;
        
    this.DataGrid.DataBind();
        }

    }
  • 相关阅读:
    Error:dojo.data.ItemFileWriteStore:Invalid item argument
    TypeError:_12.store.query is not a function
    Error:dijit.tree.TreeStoreModel:root query returned 0 items
    dijit.byId("grid") is undefined
    ORA-00600:internal error code,arguments:[keltnfy-idmlnit],[46],[1],[],[],[],[],[]
    gc cr block busy
    gc buffer busy acquire
    gc cr request
    LVS+Keepalived实现高可用集群
    关于函数授权问题
  • 原文地址:https://www.cnblogs.com/Feather/p/135853.html
Copyright © 2020-2023  润新知