HBZXF (A Hao) http://www.cnblogs.com/hbzxf When using the DataGrid page, the binding database list record will automatically generate the effect, but I found that the general meeting is "Invalid CurrentPageIndex value. It must be greater than or equal to 0 and less than PageCount." Actually solving this problem is simple, what we have to do is to determine the value of CurrentPageIndex in the DataGrid1_DeleteCommand event, and bind DataGrid according to different results .
// Retrieve the function of the database public Dataset getzcbd () {DataSet DS = new dataset (); string searchString = "SELECT ID, YY, BJ from ZC"; da = new oledbdataadapter (searchString, conn); da.fill DS, "yy"); return DS;} catch {return null;}} // Bind DataGrid private void bindGrid () {DataSet DS = New DataSet (); DS = US.Getzcbd (); if (ds! = NULL) {this.dataGrid1.datasource = DS; this.dataGrid1.database ();} else {msg.alert ("Load Data Error!", Page);}} // Remove Database Record Function Public String Deletezcbd (int BDID) ) {Int count = this.ifexisezysx (BDID); // does not have to ignore the second sentence, default count = 1 if (count <= 0) Return "false"; else {string sqlstr = "delete from zcwhere id =" bdid; OLEDBCOMMAND CMD = New OLEDBCOMMAND (SQLSTR, Conn); conn.open (); try {cmd.executenonQuery (); return "true";} catch (exception e) {return E.MESSAGE.TOSTRING ();} finally {conn .Close ();}}}}} // dataGrid1_deleteCommand event modification function priva te void DataGrid1_DeleteCommand (object source, System.Web.UI.WebControls.DataGridCommandEventArgs e) {int bdID = int.Parse (DataGrid1.DataKeys [(int) e.Item.ItemIndex] .ToString ()); string isDel = us. Deletezcbd (bdid); int currentpage = 0; if (isdel == "true") {if (this.DataGrid1.currentpageIndex == this.dataGrid1.pageCount -1) {if (this.DataGrid1.currentpageIndex == 0) { This.DataGrid1.currentpageIndex = this.dataGrid1.pagecount -1;} else {if (this.dataGrid1.items.count% this.dataGrid1.pageSize ==