this.DeletedPersonRow = dts.Tables[0].Rows[pi];
just stores a reference to the row in the DataTable. When the row is deleted its ItemArray is no longer accessible. Try cloning the DataRow:this.DeletedPersonRow = dts.Tables[0].NewRow(); this.DeletedPersonRow.ItemArray = dts.Tables[pi].ItemArray;>Ok, for a more strange reason the code started to work again.
> this.DeletedPersonRow = dts.Tables[0].Rows[pi]; //Save Person we're about to delete > Session["DeletedPersonRow"] = this.DeletedPersonRow; > this.DeletedRowIndex = pi; > ViewState["DeletedRowIndex"] = this.DeletedRowIndex; >>
>if (Session["DeletedPersonRow"] != null && Session["dts"] != null) > { > DataSet dts = (DataSet)Session["dts"]; > DataRow dr = (DataRow) Session["DeletedPersonRow"]; > dts.Tables[0].Rows.InsertAt(dr, (int)ViewState["DeletedRowIndex"]); > dts.AcceptChanges(); > Session.Remove("DeletedPersonRow") ; > ViewState.Remove("DeletedRowIndex") ; > > Session["dts"] = dts; > this.ProfilesGrid.DataBind(); > }>
>>int pi = (ProfilesGrid.PageIndex * 20) + e.RowIndex; >> >> TextBox tb; >> if (this.ProfilesGrid.Rows.Count <= pi) >> { >> tb = (TextBox) this.ProfilesGrid.Rows[e.RowIndex].Cells[13].Controls[0]; } >> else{ >> tb = (TextBox) this.ProfilesGrid.Rows[pi].Cells[13].Controls[0]; >> } >> int id = (int)Convert.ToInt16(tb.Text.ToString()); //this.ProfilesGrid.Rows[pi].Cells[14] ) >> >> string SQL = "UPDATE People SET Deleted = 1 WHERE PersonID = " + id; >> // e.CommandArgument; >> Util.DoCmd(SQL); >> >> // pi -= 1; >> >> if (Session["dts"] != null) >> { >> DataSet dts = (DataSet)Session["dts"]; >> this.DeletedPersonRow = dts.Tables[0].Rows[pi]; //Save Person we're about to delete >> Session["DeletedPersonRow"] = this.DeletedPersonRow; >> this.DeletedRowIndex = pi; >> ViewState["DeletedRowIndex"] = this.DeletedRowIndex; >> dts.Tables[0].Rows[pi].Delete(); >> dts.AcceptChanges(); >> ProfilesGrid.DataSource = dts; >> ProfilesGrid.DataBind(); >> Session["dts"]= dts; >> >> } >> // NN 05-08-08 - added LinkButton on the page itself rather than adding in run-time >> LinkButton UndoDel = (LinkButton)this.plchStatusControls.FindControl("UndoDel"); >> >> UndoDel.Text = "Undo"; >> UndoDel.Visible = true; >> UndoDel.CommandName = "Undelete"; >> UndoDel.CausesValidation = false; >> clseditmode.personid = id.ToString() ; // e.Keys["PersonID"].ToString(); >> >> UndoDel.CommandArgument = id.ToString();// e.Keys["PersonID"].ToString(); >> this.DisplayMessage("Removed " + PersonName + " click to ");