A few days ago, in a company's project, to use the DataGrid's own delete function, and implement paging, it is very simple, but it has plagued everyone in our group! Whenever a record is returned to the previous page, it will appear "Invalid CurrentPageIndex value. It must be greater than or equal to 0 and less than PageCount." Single-step commissioning and tracking it, and found that the problem is when it is DataGrid.Database (); I touched the DataGrid data source status before DATABIND (), found that DataGrid.currentPageIndex or before deleting, this is the main reason! For this error, you can have the following solutions: ideas: When you delete data in the database and determine if you need to turn your page, you need to turn your pages to correct the error of CurrentPageIndex. Implementation: In the DataGrid_Delete method, add the following code: // Delete the data in the database. . . . . . // Judgment if (DataGrid1.Count == 1 && DataGrid1.count == 1 && DataGrid1.crs.countPageIndex> 0) {dataGrid1.currentpageindex ---;} // Re-bound data bindgrid (); case two (variants): Maybe we did not use DataGrid The built-in deletion may make each time you can delete multiple records each time you can remove multiple records. Idea: Actually, I'm going to get much deletion, and save it in a variable, then DataGrid1.count and it compare, as "DataGrid1.count == 1" above, this is Can judge whether it is needed. Implementation: // Get the total number of deleted records int count = 0; foreach (DataGridItem item in DataGrid1.Items) {if (item.ItemType == ListItemType.Item || item.ItemType == ListItemType.AlternatingItem) {CheckBox ckbox = item .FindControl ("CheckBox1") as checkbox; if (ckbox! = Null && ckbox.checked) count;}} // judgment if (count == DataGrid1.Items.count && DataGrid1.currentpageIndex> 0) { DataGrid1.currentpageIndex;