0
votes

I have a Gridview that I bind some data to. I have checkboxes on each row of the Gridview that I use to delete records via Javascript. The delete works good. The problem I have is that when I do a postback on the page, all the deleted records reappear. I'm assuming this is some viewstate issue.

How can I get the Javascript deleted rows to stay deleted on a postback?

2
A good start would be posting some code - NM Pennypacker
A GridView is not a client side control and JavaScript cannot alter the data store you are using to populate your GridView. The best you can do is mark rows for deletion, even hide them if you wish. But the actual delete has to be done server side during a postback. There are many ways to accomplish this but without knowing more about your code any answer would be a guess. - fnostro
you have to databind the grid again on postback with the fresh datasource, that does not contain the deleted items ! - Legends
and ? did it help? if not post ur code ! - Legends
Thanks, I'm not in the office today to post code. I think I'm going to store the indexes I delete client side in a hidden field control. Then when the page posts back from the server, grab these indexes from the hidden field and go through the grid and remove the rows. I will try this and let you guys know if that does the trick. - Michael

2 Answers

0
votes

You have to databind the grid again on postback with the fresh datasource, that does not contain the deleted items ! If the datasource contains the old items, then they will show up again.

0
votes

I was able to get this working. Since the server doesn't know that I deleted the rows on the client, I needed to remove the rows again on the server side on post back.

How I did this was when I removed the rows on the client, I stored the indexes I removed in a hidden field. Then once the page posted back, I grab the values from this hidden field, loop through the grid's data source and remove the rows. After that I simply DataBind() the grid again.