Solved

DataGrid and Batch Update in ASP.NET

Posted on 2004-09-16
5
350 Views
Last Modified: 2012-06-27
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
0
Comment
Question by:adwat
  • 2
5 Comments
 
LVL 10

Expert Comment

by:jnhorst
ID: 12078152
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
0
 
LVL 33

Accepted Solution

by:
raterus earned 500 total points
ID: 12078558
jnhorst, I don't see why you couldn't do this with a datalist/repeater...

adwat,
As for the actual changes you need to make to the DataGrid, you need to forget about the "Edit" capabilities of the datagrid on this one.  Rather make each itemtemplate a templatecolumn, and use textboxes (or any other form control you want to use), then define an "Update" button, and when you click that you'll have to loop through each of the items of the datagrid and get the changes, then plug that into what jnhorst said.
0
 
LVL 10

Expert Comment

by:jnhorst
ID: 12149421
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
0

Featured Post

ScreenConnect 6.0 Free Trial

At ScreenConnect, partner feedback doesn't fall on deaf ears. We collected partner suggestions off of their virtual wish list and transformed them into one game-changing release: ScreenConnect 6.0. Explore all of the extras and enhancements for yourself!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question