Click here to Skip to main content
15,561,685 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
The GridView delete command is working fine but when you refresh the page from the browser directly after the delete command link is cliked the next item is deleted .ie. on every refresh click the item residing inside that index is getting deleted,, i tried resetting the RowIndex value but as u know that is ReadOnly property and cant be assigned to any value. any suggesstions

Dont care about my code and the way i am using,, try with your on code and delete an item in gridview manually and refresh the page the next item will get deleted,,

Have a look at this article,, all that Grids Having the same issue
Insert, Update, Delete in ASP.NET Gridview, DataSource as SQL Server, MS Access (mdb/accdb), XML and Framework as 2.0 / 3.0 / 3.5 / 4.0 (VS 2005/2008/2010)[^]

protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
SPSite siteCollection = new SPSite(SPContext.Current.Web.Url);

using (SPWeb web = siteCollection.OpenWeb())
{

SPListItemCollection listItems = web.Lists["FinalList"].Items;
 
int itemCount = listItems.Count;
GridViewRow row = GridView1.Rows[e.RowIndex];



if (e.RowIndex < itemCount)
{
 

listItems.Delete(e.RowIndex);
Label1.Text = "Done! ";
 

}

GridView1.Dispose();
web.Close();
web.Dispose();



}
}
Posted
Updated 6-Nov-12 23:58pm
v3
Comments
Braj_12 7-Nov-12 4:41am    
As we all know browsers store the sate of the events that event get fired whenever we refresh the page.I also have the same problem but no where i found the solution but we can manage the at page_load event.
Albarhami 7-Nov-12 4:58am    
yeah managing by redirecting is alright but thats a trick not a solution,, is there a way to override the RowIndex property and make it read and write
MT_ 7-Nov-12 4:42am    
why "SHA" tag is added ?

1 solution

As a simple solution, please redirect on same page on RowDeleted event using
C#
Response.Redirect(Request.URL.ToString())
 
Share this answer
 
v2
Comments
Albarhami 7-Nov-12 5:01am    
That trick is ok but it aint a solution
ShahPalak 7-Nov-12 5:18am    
Can you apply Update Panel? It avoids refersh the page and you can get rid from that problem.

Otherwise you will have to redirect on the same page to refresh the grid and clear the submit state.

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