Hi Jim,
I think the
=========
"Simply calling the UpdateItem method on the DetailsView or FormView object
does all of this automatically.
=========
in that article means it'll automatically cause the DetailsView supply the
updated fields as parameters to Datasource control and let the datasource
control execute the update command to do the updating to backend database.
However, since you mentioned that you want to do the update yourself, then
we should not let the automatic update being executed, yes? That's why I
suggest that we can cancel the automatic update in DetailsView's
ItemUpdating event. Also, I'm not sure on the "DataObject" object you
mentioned, for all the current databound controls, in the updating or
selecting.... events, there won't have any dataobject, only parameters
collection which contains the old fields values or new fields values and
key values.
Anyway, I admit that if manually loop through the DetailsView's cell and
extract the values from them and do the update in external submit button's
postback will make things much cleaner than using the updating event.
Thanks,
Steven Cheng
Microsoft Online Support
Get Secure!
www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
--------------------
| Thread-Topic: DetailsView and ObjectDataSource - how to get updated object
| thread-index: AcXPge9XcVqVKi3fTGCqrPWH5B2YYw==
| X-WBNR-Posting-Host: 209.137.235.2
| From: "=?Utf-8?B?SmltIEhhbW1vbmQ=?=" <Ji**************@nospam.nospam>
| References: <65**********************************@microsoft.co m>
<V5**************@TK2MSFTNGXA01.phx.gbl>
<CB**********************************@microsoft.co m>
<R5*************@TK2MSFTNGXA01.phx.gbl>
<73**********************************@microsoft.co m>
<X#**************@TK2MSFTNGXA02.phx.gbl>
<78**********************************@microsoft.co m>
<Ni**************@TK2MSFTNGXA02.phx.gbl>
<15**********************************@microsoft.co m>
<ZD*************@TK2MSFTNGXA02.phx.gbl>
| Subject: RE: DetailsView and ObjectDataSource - how to get updated object
| Date: Wed, 12 Oct 2005 16:09:02 -0700
| Lines: 320
| Message-ID: <C1**********************************@microsoft.co m>
| MIME-Version: 1.0
| Content-Type: text/plain;
| charset="Utf-8"
| Content-Transfer-Encoding: 7bit
| X-Newsreader: Microsoft CDO for Windows 2000
| Content-Class: urn:content-classes:message
| Importance: normal
| Priority: normal
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0
| Newsgroups: microsoft.public.dotnet.framework.aspnet
| NNTP-Posting-Host: TK2MSFTNGXA03.phx.gbl 10.40.2.250
| Path: TK2MSFTNGXA01.phx.gbl!TK2MSFTNGXA03.phx.gbl
| Xref: TK2MSFTNGXA01.phx.gbl
microsoft.public.dotnet.framework.aspnet:130975
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
|
| At the end of the thread,
http://forums.asp.net/908121/ShowPost.aspx, he
| states:
|
| "Simply calling the UpdateItem method on the DetailsView or FormView
object
| does all of this automatically. All of my code above is unnecessary!"
|
| I can duplicate this behavior if I pass the properties of my data object
as
| separate parameters to my updatemethod instead of passing the data
object.
| Calling DetailsView.UpdateItem method passed the values currently on the
| screen. I did not have to handle any events to accomplish this.
|
| I would still have to assign all of those values to the data object,
which
| is no cleaner than using FindControl for each field when handling a
button
| click.
|
| It seems like a bug that calling DetailsView.UpdateItem can automatically
| pass updated values as separate parameters but not as an updated data
object.
|
| "Steven Cheng[MSFT]" wrote:
|
| > Hi Jim,
| >
| > Calling DetailsView.UpdateItem method only invoke the buildin update
| > command of the DetailsView Control, if we don't intercept the
ItemUpdating
| > event ,we can not get the data objects and do our custom actions. If
using
| > the buildin update command of the datasource is ok, you can ignore the
| > itemupdating event.
| >
| > Also, as for the following thread you mentioned:
| >
| >
http://forums.asp.net/908121/ShowPost.aspx
| >
| > seems they're discussing on the ObjectDAtaSource's updating event.
Based on
| > my test (in a beta2 environment), the DetailsView's ItemUpdating
event's
| > DetailsViewUpdateEventArgs argument will contains the column values.
You
| > got an empty collection in your environment? If you feel necessary I
can
| > attach my test pages here for your reference.
| >
| > Thanks,
| >
| > Steven Cheng
| > Microsoft Online Support
| >
| > Get Secure!
www.microsoft.com/security
| > --------------------
| > | Thread-Topic: DetailsView and ObjectDataSource - how to get updated
object
| > | thread-index: AcXOeIUSFNeWcgiCSuqykb3hZuBJvQ==
| > | X-WBNR-Posting-Host: 209.137.235.2
| > | From: "=?Utf-8?B?SmltIEhhbW1vbmQ=?=" <Ji**************@nospam.nospam>
| > | References: <65**********************************@microsoft.co m>
| > <V5**************@TK2MSFTNGXA01.phx.gbl>
| > <CB**********************************@microsoft.co m>
| > <R5*************@TK2MSFTNGXA01.phx.gbl>
| > <73**********************************@microsoft.co m>
| > <X#**************@TK2MSFTNGXA02.phx.gbl>
| > <78**********************************@microsoft.co m>
| > <Ni**************@TK2MSFTNGXA02.phx.gbl>
| > | Subject: RE: DetailsView and ObjectDataSource - how to get updated
object
| > | Date: Tue, 11 Oct 2005 08:29:07 -0700
| > | Lines: 313
| > | Message-ID: <15**********************************@microsoft.co m>
| > | MIME-Version: 1.0
| > | Content-Type: text/plain;
| > | charset="Utf-8"
| > | Content-Transfer-Encoding: 7bit
| > | X-Newsreader: Microsoft CDO for Windows 2000
| > | Content-Class: urn:content-classes:message
| > | Importance: normal
| > | Priority: normal
| > | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0
| > | Newsgroups: microsoft.public.dotnet.framework.aspnet
| > | NNTP-Posting-Host: TK2MSFTNGXA03.phx.gbl 10.40.2.250
| > | Path:
| >
TK2MSFTNGXA02.phx.gbl!TK2MSFTNGXA01.phx.gbl!TK2MSF TNGP08.phx.gbl!TK2MSFTNGXA
| > 03.phx.gbl
| > | Xref: TK2MSFTNGXA02.phx.gbl
| > microsoft.public.dotnet.framework.aspnet:350002
| > | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
| > |
| > | According to the the link you provided, it sounds like calling
| > | DetailsView.UpdateItem should be sufficient without handling the
| > ItemUpdating
| > | event. Also, the following thread makes the same assertion:
| > |
| > |
http://forums.asp.net/908121/ShowPost.aspx
| > |
| > | Accessing the collections of Keys, OldValues, and NewValues in the
| > | DetailsViewUpdateEventArgs parameter ItemUpdating event handler would
not
| > | provide much benefit; however, these collections are empty.
| > |
| > |
| > | "Steven Cheng[MSFT]" wrote:
| > |
| > | > Thanks for your response Jim,
| > | >
| > | > In addition to calling the DetailsView.UpdateItem method, we also
need
| > to
| > | > register eventhandler for its ItemUpdating event, this is the
actual
| > place
| > | > where we get the dataObjects through the ItemUpdating event's
| > | > DetailsViewUpdateEventArgs parameter. We can get the key,
oldValues
| > and
| > | > NewValues and perform our own update operation and cancel this
event.
| > | >
| > | > e.g:
| > | > ===================
| > | > Protected Sub DetailsView1_ItemUpdating(ByVal sender As Object,
ByVal e
| > As
| > | > System.Web.UI.WebControls.DetailsViewUpdateEventAr gs) Handles
| > | > DetailsView1.ItemUpdating
| > | > Response.Write("<br>DetailsView1_ItemUpdating " &
| > | > DateTime.Now.Ticks)
| > | >
| > | > Dim key As String
| > | >
| > | > For Each key In e.Keys.Keys
| > | > Response.Write("<br>Key " & key & ": " &
e.Keys.Item(key))
| > | > Next
| > | >
| > | > For Each key In e.OldValues.Keys
| > | > Response.Write("<br>OldValue " & key & ": " &
| > | > e.OldValues.Item(key))
| > | > Next
| > | >
| > | > For Each key In e.NewValues.Keys
| > | > Response.Write("<br>NewValue " & key & ": " &
| > | > e.NewValues.Item(key))
| > | > Next
| > | >
| > | > End Sub
| > | > =======================
| > | >
| > | > Hope helps. Thanks,
| > | >
| > | > Steven Cheng
| > | > Microsoft Online Support
| > | >
| > | > Get Secure!
www.microsoft.com/security
| > | >
| > | >
| > | > --------------------
| > | > | Thread-Topic: DetailsView and ObjectDataSource - how to get
updated
| > object
| > | > | thread-index: AcXNxzuppqkjoBg/TQ+cRz+v5sT3OA==
| > | > | X-WBNR-Posting-Host: 209.137.235.2
| > | > | From: "=?Utf-8?B?SmltIEhhbW1vbmQ=?="
<Ji**************@nospam.nospam>
| > | > | References: <65**********************************@microsoft.co m>
| > | > <V5**************@TK2MSFTNGXA01.phx.gbl>
| > | > <CB**********************************@microsoft.co m>
| > | > <R5*************@TK2MSFTNGXA01.phx.gbl>
| > | > <73**********************************@microsoft.co m>
| > | > <X#**************@TK2MSFTNGXA02.phx.gbl>
| > | > | Subject: RE: DetailsView and ObjectDataSource - how to get
updated
| > object
| > | > | Date: Mon, 10 Oct 2005 11:20:03 -0700
| > | > | Lines: 307
| > | > | Message-ID: <78**********************************@microsoft.co m>
| > | > | MIME-Version: 1.0
| > | > | Content-Type: text/plain;
| > | > | charset="Utf-8"
| > | > | Content-Transfer-Encoding: 7bit
| > | > | X-Newsreader: Microsoft CDO for Windows 2000
| > | > | Content-Class: urn:content-classes:message
| > | > | Importance: normal
| > | > | Priority: normal
| > | > | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0
| > | > | Newsgroups: microsoft.public.dotnet.framework.aspnet
| > | > | NNTP-Posting-Host: TK2MSFTNGXA03.phx.gbl 10.40.2.250
| > | > | Path: TK2MSFTNGXA02.phx.gbl!TK2MSFTNGXA03.phx.gbl
| > | > | Xref: TK2MSFTNGXA02.phx.gbl
| > | > microsoft.public.dotnet.framework.aspnet:349765
| > | > | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
| > | > |
| > | > | Calling DataView1.UpdateItem(false) in a button click handler
does
| > cause
| > | > the
| > | > | data object's update method to be called; however, the properties
of
| > data
| > | > | object passed to the update method do not contain the current
values
| > on
| > | > the
| > | > | screen. (The DefaultMode is Edit.)
| > | > |
| > | > | "Steven Cheng[MSFT]" wrote:
| > | > |
| > | > | > Hi Jim,
| > | > | >
| > | > | > Thanks for your response.
| > | > | > yes, when using boundField with DefaultMode = EditMode, we can
not
| > use
| > | > | > Cell.Text because at that time , the field's value is stored in
a
| > | > TextBox
| > | > | > inside the Cell. In other word, we also need to use FindControl
in
| > such
| > | > | > scenario. And currently the best choice is still utilizing the
| > buildin
| > | > | > updating /updated events of the control. Also, we can
| > programmatically
| > | > | > fire the
| > | > | > DetailsView's "ItemUpdating" event by calling the
| > | > DetailsView.UpdateItem()
| > | > | > method, we can call it as long as the DetailsView is in edit
| > mode.
| > | > | >
| > | > | > So for your scenario, I think we can set the DetailsView's
default
| > mode
| > | > to
| > | > | > edit, use autogeneratedrows , then we can call
| > DetailsView.UpdateItem
| > | > in
| > | > | > a certain postback button which is outside the detailsView
control.
| >
| > | > This
| > | > | > should be the best approach currently available. How do you
think?
| > | > | >
| > | > | > #DetailsView.UpdateItem Method
| > | > | >
http://msdn2.microsoft.com/en-us/lib...US,VS.80).aspx
| > | > | >
| > | > | > BTW, as for the the limitation you mentioned, I do agree that
some
| > of
| > | > them
| > | > | > are reasonable such as make programmatical update/edit... more
| > | > convenient
| > | > | > and provide a more easy to use inteface to access the binded
data
| > from
| > | > | > DetailsView (or other single databinding control as FormView).
I'd
| > | > | > recommend you submit this feature request through MSWISH
feedback
| > | > | > (ms****@microsoft.com).
| > | > | >
| > | > | > Thanks,
| > | > | >
| > | > | > Steven Cheng
| > | > | > Microsoft Online Support
| > | > | >
| > | > | > Get Secure!
www.microsoft.com/security
| > | > | >
| > | > | >
| > | > | > --------------------
| > | > | > | Thread-Topic: DetailsView and ObjectDataSource - how to get
| > updated
| > | > object
| > | > | > | thread-index: AcXLeL3aR6m/EAKYRAK2BYxWYXVhGQ==
| > | > | > | X-WBNR-Posting-Host: 209.137.235.2
| > | > | > | From: "=?Utf-8?B?SmltIEhhbW1vbmQ=?="
| > <Ji**************@nospam.nospam>
| > | > | > | References:
<65**********************************@microsoft.co m>
| > | > | > <V5**************@TK2MSFTNGXA01.phx.gbl>
| > | > | > <CB**********************************@microsoft.co m>
| > | > | > <R5*************@TK2MSFTNGXA01.phx.gbl>
| > | > | > | Subject: RE: DetailsView and ObjectDataSource - how to get
| > updated
| > | > object
| > | > | > | Date: Fri, 7 Oct 2005 12:53:09 -0700
| > | > | > | Lines: 223
| > | > | > | Message-ID:
<73**********************************@microsoft.co m>
| > | > | > | MIME-Version: 1.0
| > | > | > | Content-Type: text/plain;
| > | > | > | charset="Utf-8"
| > | > | > | Content-Transfer-Encoding: 7bit
| > | > | > | X-Newsreader: Microsoft CDO for Windows 2000
| > | > | > | Content-Class: urn:content-classes:message
| > | > | > | Importance: normal
| > | > | > | Priority: normal
| > | > | > | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0
| > | > | > | Newsgroups: microsoft.public.dotnet.framework.aspnet
| > | > | > | NNTP-Posting-Host: TK2MSFTNGXA03.phx.gbl 10.40.2.250
| > | > | > | Path: TK2MSFTNGXA01.phx.gbl!TK2MSFTNGXA03.phx.gbl
| > | > | > | Xref: TK2MSFTNGXA01.phx.gbl
| > | > | > microsoft.public.dotnet.framework.aspnet:129912
| > | > | > | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
| > | > | > |
| > | > | > | It looks like I will not be able to escape at least one line
of
| > code
| > | > per
| > | > | > | field to manually construct a data object in a button click
| > handler.
| > | > | > |
| > | > | > | I wanted to set DefaultMode to Edit and set AutoGenerateRows
to
| > true.
| > | > | > | If AutoGenerateRows is true, then the order of the fields
seems
| > | > random
| > | > | > and
| > | > | > | thus how could they be mapped to each dvr.Cells[1].Text?
| > | > | > | Whether AutoGenerateRows is true or whether it is false and I
use
| > | > | > | asp:BoundField, if DefaultMode is Edit then dvr.Cells[1].Text
is
| > an
| > | > empty
| > | > | > | string.
| > | > | > |
| > | > | > | If I use <asp:TemplateField HeaderText= ..., then FindControl
| > works.
| > | > | > |
| > | > | > | I have 20 fields. If I use databinding, set AutoGenerateRows
to
| > true,
| > | > | > pass
| > | > | > | the dataobject as the only parameter to the update method,
and do
| > all
| > | > of
| > | > | > my
| > | > | > | processing when the user presses the auto generated Update
| > button,
| > | > then I
| > | > | > | only have to write about 5 lines of code to implement a web
UI.
| > If I
| > | > ever
| > | > | > had
| > | > | > | to add a property to my data object, the UI would
automatically
| > work.
| > | > | > |
| > | > | > | But if I am not creating a simple CRUD application and I want
a
| > | > separate
| > | > | > | button that does some action other than update, I must also
| > create 20
| > | > | > | template fields and 20 lines using FindControl.
| > | > | > |
| > | > | > | This is still easier than a UI that uses no data binding at
all,
| > but
| > | > it
| > | > | > | seems like it would have been pretty easy for MS to have
| > eliminated
|