Click here to Skip to main content
15,890,882 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
While Delete a Row in Gridview using OnRowCommand this error was occured.

Error: The GridView jobgrid fired event RowDeleting which wasnt handled.

How to resolve this error.Please reply
Posted
Comments
ManavGuru 26-Dec-11 8:15am    
Can You write your code where is error genrate
anuj_87 26-Dec-11 8:45am    
Here it is
protected void ContactsGridView_RowCommand(object sender, GridViewCommandEventArgs e)
{

// If multiple buttons are used in a GridView control, use the
// CommandName property to determine which button was clicked.
if (e.CommandName == "Load Account")
{
// Convert the row index stored in the CommandArgument
// property to an Integer.
int index = Convert.ToInt32(e.CommandArgument);

// Retrieve the row that contains the button clicked
// by the user from the Rows collection.
GridViewRow row = ContactsGridView.Rows[index];

// Create a new ListItem object for the contact in the row.
ListItem item = new ListItem();
item.Text = Server.HtmlDecode(row.Cells[1].Text);

// If the contact is not already in the ListBox, add the ListItem
// object to the Items collection of the ListBox control.
if (!ContactsListBox.Items.Contains(item))
{
ContactsListBox.Items.Add(item);
}

ContactsGridView.DeleteRow(row.RowIndex);
}

Dear Anuj,

On the deleting command execution of the code try to add all the existing data items (other than the row which you want to delete) into a datatable with same no of columns in datagrid. So this new datatable will have all the records other than the row which you want to delete then bind the same to your grid again. This will definitely solve your probelm.

Mark this as your answer if ti helps you out.

Thanks
 
Share this answer
 
Comments
anuj_87 28-Dec-11 6:13am    
Comment:Thanks, Varun for helping me out
Varun Sareen 28-Dec-11 20:42pm    
your welcome dear anuj
Dear Anuj,

When a row is being deleted the RowDeleting event is fired.
If you don't want this exception to occur, implement a method that will handle the RowDeleting event.

Here the Code goes:-

if (CommandName.ToLower().Equal("delete") && gridViewDeletingEventHandler == null)
{
   throw new HttpException("haha...I used hardcoded strings and it passed code review.");
}


So your options are:
Handle the OnRowDeleting event (even though you don't have to do anything in the event handler...really really useful). Or you can change the CommandName to something other than "Delete" like say "DoIt...DoItNow" and then you don't have to handle the event.

Please mark this as your answer if it helps you out.

Thanks
 
Share this answer
 
Hi Varun,

when i put this piece of code its gives an error like in that gridViewDeletingEventHandler

error:The name of the gridViewDeletingEventHandler does not exist in the code .

when i used this GridViewDeletedEventHandler

error:Its a type but is used like a variable

what i have to do.I have to perform that action in RowCommand event.

Please let me know.
 
Share this answer
 
Comments
anuj_87 26-Dec-11 8:40am    
??
anuj in your question u said that The GridView jobgrid fired event RowDeleting which wasnt handled.

but the code that u have given us is for ContactGridView.

check whether u want the event to be fired for contactgridview or jobGrid !!!!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900