views:

913

answers:

1

I know how to have an editable GridView along with a SqlDataSource in which each edit (update/insert/delete) is immediately persisted to the database (using the SqlDataSource's UpdateCommand, Insertcommand, etc).

What I need now is to have an editable GridView that maintains all edits in viewstate until the user presses a "Save" button elsewhere on the form.

In other words:

  1. On first load, populate the GridView from DB data
  2. User makes various edits to the data, which are not persisted to the DB yet, but which survive through any number of postbacks.
  3. User presses Save, and all the changes are persisted to the DB

I assume I'll need to write custom code to persist the data in step 3, but is there a straightforward, out-of-the-box approach to step 2?

A: 

You want to use a DataSet or DataTable and use the following:

myDataSet.AcceptChanges();

This commits the changes when you call that method on the DataSet, DataTable, or DataRow. Think of this almost like a SqlTransaction where you need to commit or rollback. Hope this helps!

see link: Accept Changes

mirezus