none
Datatable get changes method RRS feed

  • Question

  •  

    Hi,

     

            Couple of days i am struggling  getting the delected rows in gridview could any one solve my problem here i attached my code whats wrong in my code.

     

           After executing this code   dtProjectMember = dtProjectMember.GetChanges();

           the     dtProjectMember  table return the null.

           How i get the deleted rows.

     

     

    regards

    britekk

     

    protected void gvRole_RowDeleting(object sender, GridViewDeleteEventArgs e)
            {
                try
                {
                    string strRowID = gvRoleName.DataKeyNames[1];
                    string RowID = gvRoleName.DataKeys[e.RowIndex].Values[strRowID].ToString();

                    dtProjectMember = (DataTable)ViewState["dtProjectMember"];
                    dtProjectMember.AcceptChanges();
                    DataRow thisRow = dtProjectMember.Rows.Find(RowID);
                    if (thisRow != null)
                    {
                        dtProjectMember.Rows.Remove(thisRow);
                        gvRoleName.DataSource = dtProjectMember;
                        gvRoleName.DataBind();

                       dtProjectMember = dtProjectMember.GetChanges();
                       ViewState["dtProjectMember"] = dtProjectMember;

                    }
              }

                catch (Exception ex)
                {
                    ex.Message.ToString();
                }
               
            }

    Friday, September 26, 2008 12:54 PM

Answers

  • Your code is detaching the row instead of marking the row as deleted.

    After you had removed thisRow you can see the RowState == Detached instead of Deleted.

    Instead of dtProjectMember.Rows.Remove(thisRow); use thisRow.Delete();

     

    Friday, September 26, 2008 4:54 PM
    Moderator