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!