Deleting GridView’s rows


Let’s assume that ( the first time page is created ) I manually bind GridView to some data source. Is there’s a way to configure GridView to delete a row ( by pressing row’s delete button) without handling any of the delete events ( in other words, we wouldn’t try to delete a row in data source and then rebind GridView to it)? Instead, GridView would simply remove that row from its ViewState and then display all rows minus the deleted one


thanx

13.10.2009 18:07:47
2 ОТВЕТА

So then how would you end up remembering this and deleting it in the db? Why not do what may be simplier is to have a bit field in your table called Deleted. That way when someone deletes something accidentally it is still there.

Your record set would make use of a WHERE clause to filter Deleted=False

1
13.10.2009 18:14:34
I'm thinking of situations where we would want our app to bind to DB only once, and from there on application would use and manipulate that data locally and also display the results of data manipulation in GridView on each postback. Thus, the results of this manipulation would only have meaning for that particular application and thus saving the results back into DB wouldn't be an option
SourceC 13.10.2009 18:34:55
Look into ASP.net ajax and throw your datagrid in an updatepanel. The effects are very impressive.
JonH 13.10.2009 18:49:39

Instead of binding the GridView to your data source, bind it to a collection built from your data source. You can then add to, delete from and modify the collection as much as you want, without ever affecting the underlying database table.

1
13.10.2009 19:19:02
that's true, but I thought GridView had an option to automatically delete the row, without attaching any event handlers or without using ObjectDateSource.UpdateMethod
SourceC 14.10.2009 17:29:34