例如,原来你的DataGrid 有两页显示,且DataGrid.CurrentPageIndex为1,这时删除了数据,再绑定DataGrid,使DataGrid不能显示到第二页,而DataGrid.CurrentPageIndex还为1,这时就会报错。
在删除重绑DataGrid时加入
if(dt.Rows .Count % DataGrid.PageSize==0 && DataGrid.CurrentPageIndex >0)
{//dt为数据源DataTable
DataGrid.CurrentPageIndex =DataGrid.PageCount -2;
}