Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Scatter/Gather with DataRow & DataSet
Message
 
 
To
16/09/2008 15:59:47
General information
Forum:
ASP.NET
Category:
ADO.NET
Environment versions
Environment:
C# 3.0
OS:
Windows XP
Network:
Windows 2003 Server
Database:
MS SQL Server
Miscellaneous
Thread ID:
01348001
Message ID:
01348204
Views:
14
>I remember running into a similar problem recently. If you are storing session Inproc, you are really just saving a reference to the row. So the row you restore from session has rowstate of 'deleted'. Try calling DeletedPersonRow.RejectChanges() to reset the rowstate.

Thanks, Bruce. Viv nailed the problem in my other thread. So, this is the whole code now:
protected void ProfilesGrid_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        if (!clseditmode.dlt)
        {
            clseditmode.dlt = true;
            string PersonName;
            DataRowView view = ProfilesGrid.Rows[e.RowIndex].DataItem as DataRowView;
            if (view != null)
                PersonName = view["FirstName"].ToString() +
                            " " + view["LastName"].ToString();
            else
                PersonName = ProfilesGrid.Rows[e.RowIndex].Cells[6].Text + " " + ProfilesGrid.Rows[e.RowIndex].Cells[5].Text;

            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].NewRow();                
                //Save Person we're about to delete
                this.DeletedPersonRow.ItemArray = dts.Tables[0].Rows[pi].ItemArray;  
                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 ");
            //// }
        }
        else { clseditmode.dlt = false; }
    }
    /// <summary>
    /// Undelete a person
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void UndoDel_Click(object sender, EventArgs e)
    {
        LinkButton UndoDel = (LinkButton)sender;

        string SQL = "UPDATE People SET Deleted = 0 WHERE PersonID = " + UndoDel.CommandArgument;

        Util.DoCmd(SQL);   
        clseditmode.personid = null;
        this.HideForms(sender, e);
        UndoDel.Visible = false;
        // Here we want to put saved DataRow into the dataset
        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();
        }

    }
More suggestions/critique are accepted with gratitude.
If it's not broken, fix it until it is.


My Blog
Previous
Reply
Map
View

Click here to load this message in the networking platform