Solved

DataGrid and Batch Update in ASP.NET

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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
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…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

707 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

16 Experts available now in Live!

Get 1:1 Help Now