Solved

DataGrid and Batch Update in ASP.NET

Posted on 2004-09-16
5
348 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

932 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now