TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
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?
Reply
Answers (
0
)
grading system
How do You Debug an ASP.NET Web Application