Update Multiple DataBound DetailsViews With a Single Event

by Ira 27. March 2008 20:26

So I was stuck in a scenario where I needed to have multiple DetailsViews run an update command at the same time. I thought through it in my head saying to myself, "How do I click two update buttons at once?". Wouldn't it be nice if I could have a single button click event and have both DetailsView controls update at the same time? I tried simply calling the .Update() method of the ObjectDataSouce controls they were bound to and it didn't work. So I had one last thought, wouldn't it be nice if the DetailsView itself had an update method?

 

Come to find out, it does! You can call both the .UpdateItem() and .InsertItem() methods of a DetailsView in an event handler. Like a button click in this case:

or:

 So in my case it went a little something like this:

 

So it turns out that these methods are smart enough to go to the data source that your DetailsView is bound to and run the supplied insert or update method with all the correct parameters. Hope this helps you out as much as it did me!

 

kick it on DotNetKicks.com

Tags: , ,

ASP.NET | C#

Comments are closed

Powered by BlogEngine.NET 1.5.0.7
Theme by Mads Kristensen

About Me

IraIra
I'm just another developer from Florida.

 

Sponsors

Disclaimer

The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

All code samples on this website are free for download, use, and modification with no warranty nor any implied warranty. Liscensed by:

Creative Commons License
This work is licensed under a Creative Commons Attribution 3.0 United States License.