Hiral Bavisi

Hiral Bavisi

  • NA
  • 1
  • 1.6k

I can't delete some of the rows of gridview whille others can be deleted

Sep 27 2012 7:06 AM
I am using Visual studio 2010 with c# and right now creating mailbox feature.

In the inbox page i put a gridview which shows the mail from the database.

In the gridview i provided a coulumn for the checkbox throughwhich i can select row and clicking on the delete button it should delete the rows.

The problem is that the delete button click event works for some rows but cant delet some rows.

The code in click event is like
-------------------------------------------------------------------

 protected void btnDeleteSelectedMessages_Click(object sender, EventArgs e)
        {
            if (currentGridView == null)
                setCurrentGridView();

            //controleer voor elke rij welke checkbox is geselecteerd
            foreach (GridViewRow row in currentGridView.Rows)
            {
                var cb = (HtmlInputCheckBox)row.FindControl("chkPaid");
                Guid messageID = (Guid)currentGridView.DataKeys[row.DataItemIndex].Value;

                //als de checkbox is geselecteerd het bericht verwijderen
                if (cb != null && cb.Checked)
                {
                    if (currentGridView.ID.Equals("Messages"))
                        b.BussinesMessageReceiver.DeleteMessageReceiver(messageID, MessageBoxPerson);
                    else if (currentGridView.ID.Equals("MessagesSent"))
                        b.BussinesMessage.DeleteMessageSender(messageID);
                    else //MessagesDeleted
                        b.BussinesMessage.DeleteMessage(messageID, (Page.Server.MapPath("~/Upload/") + messageID));
                    continue;
                }
            }
            btnDeleteSelectedMessages.Enabled = true;
            selectLocation.Visible = true;
            clearSelectedMessageSession();

            //Update the GridView
            BindGridView();
        }
----------------------------------------------------------------------------------
it will go in the DeleteMessageReceiver() which is like this

--------------------------------------------------------------------------------
 public void DeleteMessageReceiver(Guid messageId, Guid personId)
        {
            var rc = GetMessageReceiver(messageId, personId);
            rc.LocationID = BussinesCollection.BussinesMessage.GetLocationId("Verwijderde Items");
            rc.Deleted = true;
            Db.SubmitChanges();
        }
---------------------------------------------------------------------------

It shows error in the

rc.LocationID = BussinesCollection.BussinesMessage.GetLocationId(""Verwijderde Items");

the error is
"Object reference not set to an instance of an object."

But the same method does not showing any error in for some other rows.

can anyone help?