1:分页操作错误
原因:每一页都是单独的绑定,就会存在下标越界的问题。
//count为所有记录的总条数=12,而DataGrid.PageSize=10
for(int rows = 0;rows < count;rows++)
DataGrid1.Items[rows].Cells [8]="test";
当点击下一页时,就会出现越界的错误,以为第二页的index也是从0开始
2:改变DataGrid.PageSize时候的错误;无效的 CurrentPageIndex 值。它必须大于等于 0 且小于 PageCount。
问题出在了DataGrid.DataBind();的时候。我调了一下DataBind()之前的DataGrid数据源状态,发现DataGrid.CurrentPageIndex还是删除前的,这是出错的主要原因。
解决方法:在适当位置(example:button_click事件中)添加:
if( DataGrid.CurrentPageIndex > 0 )
{
DataGrid.CurrentPageIndex = 0;
}
参考:
阅读(1388) | 评论(0) | 转发(0) |