在绑定之前做判断:
If ds.Tables("tbldepartment").Rows.Count = MyDataGrid.PageSize * MyDataGrid.CurrentPageIndex Then
MyDataGrid.CurrentPageIndex -= 1
End If
MyDataGrid.DataBind()
If ds.Tables("tbldepartment").Rows.Count = MyDataGrid.PageSize * MyDataGrid.CurrentPageIndex Then
MyDataGrid.CurrentPageIndex -= 1
End If
MyDataGrid.DataBind()
MyDataGrid.DataSource=ds.Tables("tbldepartment").DefaultView
If ds.Tables("tbldepartment").Rows.Count = MyDataGrid.PageSize * MyDataGrid.CurrentPageIndex Then
MyDataGrid.CurrentPageIndex -= 1
End If
MyDataGrid.DataBind()