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.DetailsViewUpdateEventArgs) 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=?=" <
[email protected]>
| References: <
[email protected]>
<
[email protected]>
<
[email protected]>
<
[email protected]>
<
[email protected]>
<X#
[email protected]>
| Subject: RE: DetailsView and ObjectDataSource - how to get updated object
| Date: Mon, 10 Oct 2005 11:20:03 -0700
| Lines: 307
| Message-ID: <
[email protected]>
| 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/library/ms155863(en-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
| > (
[email protected]).
| >
| > 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=?=" <
[email protected]>
| > | References: <
[email protected]>
| > <
[email protected]>
| > <
[email protected]>
| > <
[email protected]>
| > | Subject: RE: DetailsView and ObjectDataSource - how to get updated
object
| > | Date: Fri, 7 Oct 2005 12:53:09 -0700
| > | Lines: 223
| > | Message-ID: <
[email protected]>
| > | 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
the
| > need
| > | to write and maintain these additional 40 lines of code.
| > |
| > | "Steven Cheng[MSFT]" wrote:
| > |
| > | > Thanks for your response Jim,
| > | >
| > | > Yes ,the DateItem is used during the DataBinding period, after that
,
| > in
| > | > the sequential page reuqest, it's null. So we can not retrieve the
| > | > DataObject back through it in sequential postback events. If you do
| > need to
| > | > retrieve the record values in postback event, we have the following
| > means:
| > | >
| > | > 1. Use BoundFields, and use the DetailsView.Rows collection and
| > | > DetailsViewRow.Cells collection to access the TableCell.Text which
| > stored
| > | > the current record's certain fields values. For example, suppose we
| > have
| > | > the following fields in detailsView:
| > | >
| > | > <Fields>
| > | > <asp:BoundField DataField="CategoryID"
| > | > HeaderText="CategoryID" InsertVisible="False"
| > | > ReadOnly="True" SortExpression="CategoryID" />
| > | > <asp:BoundField DataField="CategoryName"
| > | > HeaderText="CategoryName" SortExpression="CategoryName" />
| > | > <asp:BoundField DataField="Description"
| > | > HeaderText="Description" SortExpression="Description" />
| > | >
| > | > </Fields>
| > | >
| > | > ,we can use the following code to display all the values displayed
in
| > UI:
| > | >
| > | > protected void Button1_Click(object sender, EventArgs e)
| > | > {
| > | >
| > | > foreach (DetailsViewRow dvr in DetailsView1.Rows)
| > | > {
| > | > Response.Write("<br> " + dvr.Cells[1].Text);
| > | > }
| > | > }
| > | >
| > | > we will get three rows ,each row represent a field. (CategoryID,
| > | > CategoryName and Description)
| > | >
| > | > 2. Also, since you're not using the buildin edit/update funciton,
we
| > can
| > | > replace the boundfields with our custom template fields instead.
for
| > | > exmple, we define the following template fields in DetailsView
| > | >
| > | > <asp:TemplateField >
| > | > <ItemTemplate>
| > | > <asp:TextBox ID="txtCategoryID" runat="server"
| > | > Text='<%# Eval("CategoryID") %>' />
| > | > </ItemTemplate>
| > | > </asp:TemplateField>
| > | >
| > | > Then in postback code , we can use Findcontrol to retrieve the
TextBox
| > | > Reference:
| > | >
| > | > TextBox txt = DetailsView1.FindControl("txtCategoryID") as TextBox;
| > | > Response.Write("<br>txtCategoryID: " + txt.Text);
| > | >
| > | >
| > | > Both the #1 and #2 only apply to the current displayed record.
| > | >
| > | > Thanks,
| > | >
| > | > Steven Cheng
| > | > Microsoft Online Support
| > | >
| > | > Get Secure!
www.microsoft.com/security
| > | >
| > | >
| > | >
| > | > --------------------
| > | > | Thread-Topic: DetailsView and ObjectDataSource - how to get
updated
| > object
| > | > | thread-index: AcXKsvD0F+uHjQARQnK7GtRm1KeQJA==
| > | > | X-WBNR-Posting-Host: 209.137.235.2
| > | > | From: "=?Utf-8?B?SmltIEhhbW1vbmQ=?="
<
[email protected]>
| > | > | References: <
[email protected]>
| > | > <
[email protected]>
| > | > | Subject: RE: DetailsView and ObjectDataSource - how to get
updated
| > object
| > | > | Date: Thu, 6 Oct 2005 13:17:14 -0700
| > | > | Lines: 83
| > | > | Message-ID: <
[email protected]>
| > | > | 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:129593
| > | > | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
| > | > |
| > | > | What the developer really needs is a way to specify that the
DataItem
| > | > | property of the DetailView should be populated (with the data
object)
| > | > when
| > | > | the user presses an ordinary button so that a dataobject with the
| > values
| > | > | currently on screen will be available in the event handler for
that
| > | > button
| > | > | click. The DataItem property is always always null, when I need
it.
| > | > |
| > | > | In addition to saving the developer from constructing a data
object
| > from
| > | > a
| > | > | collection of new values, this would enable the developer to
store
| > the
| > | > object
| > | > | in the session, which is not availble in the select and update
| > methods of
| > | > the
| > | > | data object. Also, it would permit a more intuitive UI because
| > buttons
| > | > would
| > | > | not have to be in the DetailView except when that makes sense.
| > | > |
| > | > |
| > | > | "Steven Cheng[MSFT]" wrote:
| > | > |
| > | > | > Hi Jim,
| > | > | >
| > | > | > Welcome to ASPNET newsgroup.
| > | > | > As for the ASP.NET 2.0's DetailsView control , based on my
| > research,
| > | > after
| > | > | > we perform DataBinding on the DetailsView, all the datas from
| > | > DataSource
| > | > | > are persisted in the DetailsView through ViewState, and they're
not
| > | > | > directly exposed to us. Currently if we need to retrieve the
| > OldValues
| > | > and
| > | > | > NewValues and key values from the paramters collection ,the
best
| > means
| > | > is
| > | > | > utilize the detailsView's buildin Updating command. And if you
| > don't
| > | > want
| > | > | > to use the buildin edit/update/cancel button, of course we can
use
| > our
| > | > own
| > | > | > buttons, we can add a custom field and put our own submit or
| > linkbutton
| > | > in
| > | > | > it. But we need to set the proper commandName for them such as
| > "Edit",
| > | > | > "Update", "Cancel" ...
| > | > | >
| > | > | > 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: AcXI+V3yM7Jnzt0DTLaRAvFSeSyfuQ==
| > | > | > | X-WBNR-Posting-Host: 209.137.235.2
| > | > | > | From: "=?Utf-8?B?SmltIEhhbW1vbmQ=?="
| > <
[email protected]>
| > | > | > | Subject: DetailsView and ObjectDataSource - how to get
updated
| > object
| > | > | > | Date: Tue, 4 Oct 2005 08:36:19 -0700
| > | > | > | Lines: 13
| > | > | > | Message-ID:
<
[email protected]>
| > | > | > | 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:128896
| > | > | > | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
| > | > | > |
| > | > | > | I am passing the whole object instead or parameters in my
select
| > and
| > | > | > update
| > | > | > | methods.
| > | > | > |
| > | > | > | I can get the updated object if I set UpdateMethod, let
ASP.NET
|