Link to home
Start Free TrialLog in
Avatar of adwat
adwat

asked on

DataGrid and Batch Update in ASP.NET

Sir,

In ASP.NET, I want to display number of records with many column and Edit many records and many columns.  After my edit I  want to update all the edited records in one click.  When I check with ASP.NET, I have to edit one record, update it and then go for another record.  I don't want to do like this.  Is it possible to Edit and Update Many records at a time? (Like Batch Update)  Please advise me in this matter.  

Thanks
Avatar of jnhorst
jnhorst

Yes, it is:

First of all, you have to use a Dataset rather than a DataReader or Repeater.  The Dataset is what will keep track of your changes before you fire them off to the database as a batch.  You will need to create a data adapter with a select command and an update command that will either Fill your datatable or Update it when you have made all your changes.  Then when you make changes to data in a row in your grid, you will save those changes to the underlying dataset.  Once all changes have been made, you call the data adapter's Update() method (likely in the click event of a button) and the data adapter recognizes which rows of data were changed and fires the update command SQL for these rows.

The only challenge with this is it taxes the viewstate.  The only way to make it work reasonably is to use paging on the grid to keep the amount of data viewstate has to keep down to a manageable level.  But when the user navigates to another page in the grid, the Update() method has to be called for the previous page to save any changes.

If you need help putting these things together, I'd be happy to help.

John
ASKER CERTIFIED SOLUTION
Avatar of raterus
raterus
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Raterus is correct.  I incorrectly lumped DataReader with Repeater/DataList.  This can certainly be done done with a Repeater/DataList.  It should just be bound to a data table in a dataset.

John