473,287 Members | 1,964 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,287 software developers and data experts.

DetailsView and ObjectDataSource - how to get updated object

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 autogenerate
an update button, and then press update after making changes, but I don't
want that update button.

How can I get the updated object when the user presses one of my other
action buttons?

Thanks,

Jim
Nov 19 '05 #1
12 8650
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=?=" <Ji**************@nospam.nospam>
| Subject: DetailsView and ObjectDataSource - how to get updated object
| Date: Tue, 4 Oct 2005 08:36:19 -0700
| Lines: 13
| Message-ID: <65**********************************@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: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
autogenerate
| an update button, and then press update after making changes, but I don't
| want that update button.
|
| How can I get the updated object when the user presses one of my other
| action buttons?
|
| Thanks,
|
| Jim
|

Nov 19 '05 #2
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=?=" <Ji**************@nospam.nospam>
| Subject: DetailsView and ObjectDataSource - how to get updated object
| Date: Tue, 4 Oct 2005 08:36:19 -0700
| Lines: 13
| Message-ID: <65**********************************@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: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
autogenerate
| an update button, and then press update after making changes, but I don't
| want that update button.
|
| How can I get the updated object when the user presses one of my other
| action buttons?
|
| Thanks,
|
| Jim
|

Nov 19 '05 #3
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=?=" <Ji**************@nospam.nospam>
| References: <65**********************************@microsoft.co m>
<V5**************@TK2MSFTNGXA01.phx.gbl>
| Subject: RE: DetailsView and ObjectDataSource - how to get updated object
| Date: Thu, 6 Oct 2005 13:17:14 -0700
| Lines: 83
| Message-ID: <CB**********************************@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: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=?=" <Ji**************@nospam.nospam>
| > | Subject: DetailsView and ObjectDataSource - how to get updated object
| > | Date: Tue, 4 Oct 2005 08:36:19 -0700
| > | Lines: 13
| > | Message-ID: <65**********************************@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: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
| > autogenerate
| > | an update button, and then press update after making changes, but I
don't
| > | want that update button.
| > |
| > | How can I get the updated object when the user presses one of my
other
| > | action buttons?
| > |
| > | Thanks,
| > |
| > | Jim
| > |
| >
| >
|

Nov 19 '05 #4
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=?=" <Ji**************@nospam.nospam>
| References: <65**********************************@microsoft.co m>
<V5**************@TK2MSFTNGXA01.phx.gbl>
| Subject: RE: DetailsView and ObjectDataSource - how to get updated object
| Date: Thu, 6 Oct 2005 13:17:14 -0700
| Lines: 83
| Message-ID: <CB**********************************@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: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=?=" <Ji**************@nospam.nospam>
| > | Subject: DetailsView and ObjectDataSource - how to get updated object
| > | Date: Tue, 4 Oct 2005 08:36:19 -0700
| > | Lines: 13
| > | Message-ID: <65**********************************@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: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
| > autogenerate
| > | an update button, and then press update after making changes, but I
don't
| > | want that update button.
| > |
| > | How can I get the updated object when the user presses one of my
other
| > | action buttons?
| > |
| > | Thanks,
| > |
| > | Jim
| > |
| >
| >
|

Nov 19 '05 #5
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 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=?=" <Ji**************@nospam.nospam>
| > | References: <65**********************************@microsoft.co m>
| > <V5**************@TK2MSFTNGXA01.phx.gbl>
| > | Subject: RE: DetailsView and ObjectDataSource - how to get updated
object
| > | Date: Thu, 6 Oct 2005 13:17:14 -0700
| > | Lines: 83
| > | Message-ID: <CB**********************************@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: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=?="
<Ji**************@nospam.nospam>
| > | > | Subject: DetailsView and ObjectDataSource - how to get updated
object
| > | > | Date: Tue, 4 Oct 2005 08:36:19 -0700
| > | > | Lines: 13
| > | > | Message-ID: <65**********************************@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: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
| > | > autogenerate
| > | > | an update button, and then press update after making changes, but
I
| > don't
| > | > | want that update button.
| > | > |
| > | > | How can I get the updated object when the user presses one of my
| > other
| > | > | action buttons?
| > | > |
| > | > | Thanks,
| > | > |
| > | > | Jim
| > | > |
| > | >
| > | >
| > |
| >
| >
|

Nov 19 '05 #6
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 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=?=" <Ji**************@nospam.nospam>
| > | References: <65**********************************@microsoft.co m>
| > <V5**************@TK2MSFTNGXA01.phx.gbl>
| > | Subject: RE: DetailsView and ObjectDataSource - how to get updated
object
| > | Date: Thu, 6 Oct 2005 13:17:14 -0700
| > | Lines: 83
| > | Message-ID: <CB**********************************@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: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=?="
<Ji**************@nospam.nospam>
| > | > | Subject: DetailsView and ObjectDataSource - how to get updated
object
| > | > | Date: Tue, 4 Oct 2005 08:36:19 -0700
| > | > | Lines: 13
| > | > | Message-ID: <65**********************************@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: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

Nov 19 '05 #7
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
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=?="
<Ji**************@nospam.nospam>
| > | > | References: <65**********************************@microsoft.co m>
| > | > <V5**************@TK2MSFTNGXA01.phx.gbl>
| > | > | Subject: RE: DetailsView and ObjectDataSource - how to get
updated
| > object
| > | > | Date: Thu, 6 Oct 2005 13:17:14 -0700
| > | > | Lines: 83
| > | > | Message-ID: <CB**********************************@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: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=?="
| > <Ji**************@nospam.nospam>
| > | > | > | Subject: DetailsView and ObjectDataSource - how to get
updated
| > object
| > | > | > | Date: Tue, 4 Oct 2005 08:36:19 -0700
| > | > | > | Lines: 13
| > | > | > | Message-ID:
<65**********************************@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: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
|

Nov 19 '05 #8
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
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=?="
<Ji**************@nospam.nospam>
| > | > | References: <65**********************************@microsoft.co m>
| > | > <V5**************@TK2MSFTNGXA01.phx.gbl>
| > | > | Subject: RE: DetailsView and ObjectDataSource - how to get
updated
| > object
| > | > | Date: Thu, 6 Oct 2005 13:17:14 -0700
| > | > | Lines: 83
| > | > | Message-ID: <CB**********************************@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

Nov 19 '05 #9
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
| > 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=?="
| > <Ji**************@nospam.nospam>
| > | > | > | References:
<65**********************************@microsoft.co m>
| > | > | > <V5**************@TK2MSFTNGXA01.phx.gbl>
| > | > | > | Subject: RE: DetailsView and ObjectDataSource - how to get
| > updated
| > | > object
| > | > | > | Date: Thu, 6 Oct 2005 13:17:14 -0700
| > | > | > | Lines: 83
| > | > | > | Message-ID:
<CB**********************************@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
|

Nov 19 '05 #10
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

Nov 19 '05 #11
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
|

Nov 19 '05 #12
thanks, but I have resolved this issue and posted the solution at:

http://codeproject.com/useritems/Obj...ce_wo_code.asp

"Steven Cheng[MSFT]" wrote:
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

Nov 19 '05 #13

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: sck10 | last post by:
Hello, I have a GridView that list all the employees in our group. My select button (link) when clicked will open a DetailsView control of the employee selected. I have one BoundField in the...
3
by: chrisn | last post by:
Hi, (Using ASP.Net 2.0) I have a wizard control inside a detailsview control. When I attempt to call the InsertItem method on the DetailsView I get an error "ObjectDataSource...
7
by: studio60podcast | last post by:
I have a gridview and a details view in a page. The two are hooked up, so that when a row is selected in the GridView, the DetailsView displays the details. But, what I'm trying to accomplish is...
1
by: Mark Stafford | last post by:
I am attempting to use a DetailsView control to view some data where the fields returned by the database are determined at runtime. I create the TemplateFields on the fly using a class that...
0
by: tarscher | last post by:
Hi all, I use a detailsview to insert a record in a database. The detailsview is linked via a objectdatasource to an insert business object that expects an object (class I wrote myself. How can...
0
by: sansie | last post by:
Hi, I have a page which is basically a details view(in inset mode) inside a datalist. The problem is I want to set the field "invoiceID" (of the detailsview) to an invoiceID coming through the...
1
by: ledneh | last post by:
I've been working on concurrency checking for an application I'm building, and a minor part of it has me slightly stumped. I've got a DetailsView that populates from an ObjectDataSource, using...
5
by: =?Utf-8?B?bXBhaW5l?= | last post by:
Hello, I am completely lost as to why I can't update a DropDownList inside a DetailsView after I perform an insert into an object datasource. I tried to simply it down to the core demostration:...
2
by: bednarz.thomas | last post by:
I have the following business Object(s): public class ParentObject { public ParentObject(string somestring) { ...- } ....
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.