• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 716
  • Last Modified:

How to edit gridview "offline" then update later?

Here's what I have: A webform with a gridview and a form section to "add" records. The gridview is databound to an objectdatasource. It has an edit and delete button. A "submit changes to database" button is at the bottom of the form (this actually submits the adds, edits and deletes to the db).

Here's what I want: For the user to be able to add, edit and delete records/gridview. BUT, it will NOT actually update the database UNTIL the button is pressed. So, they are really editing the data OFFLINE then "syncing" it, in a way, with the database.

Questions: How can I go about letting them modify the data "offline"? How can I update the database with the changes most efficiently?
  • 2
1 Solution
Get a datatable from the DB - same as you would when you get a datatable and bind it to a control in codebehind.

Store the datatable in a session, when the user updates stuff, update the datatable stored in the session.

When you want to update the actual DB with the changes, update it from the datatable you have stored in your session.
RobertNZanaAuthor Commented:
CodeCruiser: Thanks, but that link doesn't help my situation at all.

Si_hibbard and others: So you are saying to retrieve the dataset into a session var and bind the gridview to this? Then update this dataset (from the session var)? If so how can I "sync" the 2 datasets the easiest, most efficient way? I'm sure I dont need to loop thru each record 1 by 1. Is there an isdirty, etc... way to sync it? I'm sure there is.
The first step is easy, just get the datatable, bind it to the gridview, and also store it in a session.

On updates, you need to handle yourself, load the datatable from the session, update it, rebind it to the gridview and save it back in the session.

On complete you then need to update the DB from the saved session.

How you do these depends on how you are building your code - i.e. using a data access layer (datasets) or whatever.

I did find this link, it may be useful or not -> http://www.dotnetspider.com/resources/20462-Bind-Gridview-from-Session-Then-Edit-Update.aspx

Maybe you can search a bit more on 'binding gridview from session', 'storing datatable in session', 'sql update from datatable session' to give you some ideas to suit your solution.

Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now