DetailsView and ObjectDataSource - how to get updated object

Discussion in 'ASP .Net' started by =?Utf-8?B?SmltIEhhbW1vbmQ=?=, Oct 4, 2005.

  1. 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
     
    =?Utf-8?B?SmltIEhhbW1vbmQ=?=, Oct 4, 2005
    #1
    1. Advertising

  2. 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=?=" <>
    | Subject: DetailsView and ObjectDataSource - how to get updated object
    | Date: Tue, 4 Oct 2005 08:36:19 -0700
    | Lines: 13
    | Message-ID: <>
    | 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
    |
     
    Steven Cheng[MSFT], Oct 5, 2005
    #2
    1. Advertising

  3. 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=?=" <>
    > | Subject: DetailsView and ObjectDataSource - how to get updated object
    > | Date: Tue, 4 Oct 2005 08:36:19 -0700
    > | Lines: 13
    > | Message-ID: <>
    > | 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
    > |
    >
    >
     
    =?Utf-8?B?SmltIEhhbW1vbmQ=?=, Oct 6, 2005
    #3
  4. 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=?=" <>
    | References: <>
    <>
    | Subject: RE: DetailsView and ObjectDataSource - how to get updated object
    | Date: Thu, 6 Oct 2005 13:17:14 -0700
    | Lines: 83
    | Message-ID: <>
    | 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=?=" <>
    | > | Subject: DetailsView and ObjectDataSource - how to get updated object
    | > | Date: Tue, 4 Oct 2005 08:36:19 -0700
    | > | Lines: 13
    | > | Message-ID: <>
    | > | 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
    | > |
    | >
    | >
    |
     
    Steven Cheng[MSFT], Oct 7, 2005
    #4
  5. 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=?=" <>
    > | References: <>
    > <>
    > | Subject: RE: DetailsView and ObjectDataSource - how to get updated object
    > | Date: Thu, 6 Oct 2005 13:17:14 -0700
    > | Lines: 83
    > | Message-ID: <>
    > | 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=?=" <>
    > | > | Subject: DetailsView and ObjectDataSource - how to get updated object
    > | > | Date: Tue, 4 Oct 2005 08:36:19 -0700
    > | > | Lines: 13
    > | > | Message-ID: <>
    > | > | 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
    > | > |
    > | >
    > | >
    > |
    >
    >
     
    =?Utf-8?B?SmltIEhhbW1vbmQ=?=, Oct 7, 2005
    #5
  6. Hi Jim,

    Thanks for your response.
    yes, when using boundField with DefaultMode = EditMode, we can not use
    Cell.Text because at that time , the field's value is stored in a TextBox
    inside the Cell. In other word, we also need to use FindControl in such
    scenario. And currently the best choice is still utilizing the buildin
    updating /updated events of the control. Also, we can programmatically
    fire the
    DetailsView's "ItemUpdating" event by calling the DetailsView.UpdateItem()
    method, we can call it as long as the DetailsView is in edit mode.

    So for your scenario, I think we can set the DetailsView's default mode to
    edit, use autogeneratedrows , then we can call DetailsView.UpdateItem in
    a certain postback button which is outside the detailsView control. This
    should be the best approach currently available. How do you think?

    #DetailsView.UpdateItem Method
    http://msdn2.microsoft.com/en-us/library/ms155863(en-US,VS.80).aspx

    BTW, as for the the limitation you mentioned, I do agree that some of them
    are reasonable such as make programmatical update/edit... more convenient
    and provide a more easy to use inteface to access the binded data from
    DetailsView (or other single databinding control as FormView). I'd
    recommend you submit this feature request through MSWISH feedback
    ().

    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=?=" <>
    | References: <>
    <>
    <>
    <>
    | Subject: RE: DetailsView and ObjectDataSource - how to get updated object
    | Date: Fri, 7 Oct 2005 12:53:09 -0700
    | Lines: 223
    | Message-ID: <>
    | 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=?=" <>
    | > | References: <>
    | > <>
    | > | Subject: RE: DetailsView and ObjectDataSource - how to get updated
    object
    | > | Date: Thu, 6 Oct 2005 13:17:14 -0700
    | > | Lines: 83
    | > | Message-ID: <>
    | > | 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=?="
    <>
    | > | > | Subject: DetailsView and ObjectDataSource - how to get updated
    object
    | > | > | Date: Tue, 4 Oct 2005 08:36:19 -0700
    | > | > | Lines: 13
    | > | > | Message-ID: <>
    | > | > | 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
    | > | > |
    | > | >
    | > | >
    | > |
    | >
    | >
    |
     
    Steven Cheng[MSFT], Oct 10, 2005
    #6
  7. Calling DataView1.UpdateItem(false) in a button click handler does cause the
    data object's update method to be called; however, the properties of data
    object passed to the update method do not contain the current values on the
    screen. (The DefaultMode is Edit.)

    "Steven Cheng[MSFT]" wrote:

    > Hi Jim,
    >
    > Thanks for your response.
    > yes, when using boundField with DefaultMode = EditMode, we can not use
    > Cell.Text because at that time , the field's value is stored in a TextBox
    > inside the Cell. In other word, we also need to use FindControl in such
    > scenario. And currently the best choice is still utilizing the buildin
    > updating /updated events of the control. Also, we can programmatically
    > fire the
    > DetailsView's "ItemUpdating" event by calling the DetailsView.UpdateItem()
    > method, we can call it as long as the DetailsView is in edit mode.
    >
    > So for your scenario, I think we can set the DetailsView's default mode to
    > edit, use autogeneratedrows , then we can call DetailsView.UpdateItem in
    > a certain postback button which is outside the detailsView control. This
    > should be the best approach currently available. How do you think?
    >
    > #DetailsView.UpdateItem Method
    > http://msdn2.microsoft.com/en-us/library/ms155863(en-US,VS.80).aspx
    >
    > BTW, as for the the limitation you mentioned, I do agree that some of them
    > are reasonable such as make programmatical update/edit... more convenient
    > and provide a more easy to use inteface to access the binded data from
    > DetailsView (or other single databinding control as FormView). I'd
    > recommend you submit this feature request through MSWISH feedback
    > ().
    >
    > 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=?=" <>
    > | References: <>
    > <>
    > <>
    > <>
    > | Subject: RE: DetailsView and ObjectDataSource - how to get updated object
    > | Date: Fri, 7 Oct 2005 12:53:09 -0700
    > | Lines: 223
    > | Message-ID: <>
    > | 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=?=" <>
    > | > | References: <>
    > | > <>
    > | > | Subject: RE: DetailsView and ObjectDataSource - how to get updated
    > object
    > | > | Date: Thu, 6 Oct 2005 13:17:14 -0700
    > | > | Lines: 83
    > | > | Message-ID: <>
    > | > | 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=?="
    > <>
    > | > | > | Subject: DetailsView and ObjectDataSource - how to get updated
    > object
    > | > | > | Date: Tue, 4 Oct 2005 08:36:19 -0700
    > | > | > | Lines: 13
    > | > | > | Message-ID: <>
    > | > | > | 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
     
    =?Utf-8?B?SmltIEhhbW1vbmQ=?=, Oct 10, 2005
    #7
  8. Thanks for your response Jim,

    In addition to calling the DetailsView.UpdateItem method, we also need to
    register eventhandler for its ItemUpdating event, this is the actual place
    where we get the dataObjects through the ItemUpdating event's
    DetailsViewUpdateEventArgs parameter. We can get the key, oldValues and
    NewValues and perform our own update operation and cancel this event.

    e.g:
    ===================
    Protected Sub DetailsView1_ItemUpdating(ByVal sender As Object, ByVal e As
    System.Web.UI.WebControls.DetailsViewUpdateEventArgs) Handles
    DetailsView1.ItemUpdating
    Response.Write("<br>DetailsView1_ItemUpdating " &
    DateTime.Now.Ticks)

    Dim key As String

    For Each key In e.Keys.Keys
    Response.Write("<br>Key " & key & ": " & e.Keys.Item(key))
    Next

    For Each key In e.OldValues.Keys
    Response.Write("<br>OldValue " & key & ": " &
    e.OldValues.Item(key))
    Next

    For Each key In e.NewValues.Keys
    Response.Write("<br>NewValue " & key & ": " &
    e.NewValues.Item(key))
    Next

    End Sub
    =======================

    Hope helps. Thanks,

    Steven Cheng
    Microsoft Online Support

    Get Secure! www.microsoft.com/security


    --------------------
    | Thread-Topic: DetailsView and ObjectDataSource - how to get updated object
    | thread-index: AcXNxzuppqkjoBg/TQ+cRz+v5sT3OA==
    | X-WBNR-Posting-Host: 209.137.235.2
    | From: "=?Utf-8?B?SmltIEhhbW1vbmQ=?=" <>
    | References: <>
    <>
    <>
    <>
    <>
    <X#>
    | Subject: RE: DetailsView and ObjectDataSource - how to get updated object
    | Date: Mon, 10 Oct 2005 11:20:03 -0700
    | Lines: 307
    | Message-ID: <>
    | MIME-Version: 1.0
    | Content-Type: text/plain;
    | charset="Utf-8"
    | Content-Transfer-Encoding: 7bit
    | X-Newsreader: Microsoft CDO for Windows 2000
    | Content-Class: urn:content-classes:message
    | Importance: normal
    | Priority: normal
    | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0
    | Newsgroups: microsoft.public.dotnet.framework.aspnet
    | NNTP-Posting-Host: TK2MSFTNGXA03.phx.gbl 10.40.2.250
    | Path: TK2MSFTNGXA02.phx.gbl!TK2MSFTNGXA03.phx.gbl
    | Xref: TK2MSFTNGXA02.phx.gbl
    microsoft.public.dotnet.framework.aspnet:349765
    | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
    |
    | Calling DataView1.UpdateItem(false) in a button click handler does cause
    the
    | data object's update method to be called; however, the properties of data
    | object passed to the update method do not contain the current values on
    the
    | screen. (The DefaultMode is Edit.)
    |
    | "Steven Cheng[MSFT]" wrote:
    |
    | > Hi Jim,
    | >
    | > Thanks for your response.
    | > yes, when using boundField with DefaultMode = EditMode, we can not use
    | > Cell.Text because at that time , the field's value is stored in a
    TextBox
    | > inside the Cell. In other word, we also need to use FindControl in such
    | > scenario. And currently the best choice is still utilizing the buildin
    | > updating /updated events of the control. Also, we can programmatically
    | > fire the
    | > DetailsView's "ItemUpdating" event by calling the
    DetailsView.UpdateItem()
    | > method, we can call it as long as the DetailsView is in edit mode.
    | >
    | > So for your scenario, I think we can set the DetailsView's default mode
    to
    | > edit, use autogeneratedrows , then we can call DetailsView.UpdateItem
    in
    | > a certain postback button which is outside the detailsView control.
    This
    | > should be the best approach currently available. How do you think?
    | >
    | > #DetailsView.UpdateItem Method
    | > http://msdn2.microsoft.com/en-us/library/ms155863(en-US,VS.80).aspx
    | >
    | > BTW, as for the the limitation you mentioned, I do agree that some of
    them
    | > are reasonable such as make programmatical update/edit... more
    convenient
    | > and provide a more easy to use inteface to access the binded data from
    | > DetailsView (or other single databinding control as FormView). I'd
    | > recommend you submit this feature request through MSWISH feedback
    | > ().
    | >
    | > 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=?=" <>
    | > | References: <>
    | > <>
    | > <>
    | > <>
    | > | Subject: RE: DetailsView and ObjectDataSource - how to get updated
    object
    | > | Date: Fri, 7 Oct 2005 12:53:09 -0700
    | > | Lines: 223
    | > | Message-ID: <>
    | > | 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=?="
    <>
    | > | > | References: <>
    | > | > <>
    | > | > | Subject: RE: DetailsView and ObjectDataSource - how to get
    updated
    | > object
    | > | > | Date: Thu, 6 Oct 2005 13:17:14 -0700
    | > | > | Lines: 83
    | > | > | Message-ID: <>
    | > | > | 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=?="
    | > <>
    | > | > | > | Subject: DetailsView and ObjectDataSource - how to get
    updated
    | > object
    | > | > | > | Date: Tue, 4 Oct 2005 08:36:19 -0700
    | > | > | > | Lines: 13
    | > | > | > | Message-ID:
    <>
    | > | > | > | 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
    |
     
    Steven Cheng[MSFT], Oct 11, 2005
    #8
  9. 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.DetailsViewUpdateEventArgs) Handles
    > DetailsView1.ItemUpdating
    > Response.Write("<br>DetailsView1_ItemUpdating " &
    > DateTime.Now.Ticks)
    >
    > Dim key As String
    >
    > For Each key In e.Keys.Keys
    > Response.Write("<br>Key " & key & ": " & e.Keys.Item(key))
    > Next
    >
    > For Each key In e.OldValues.Keys
    > Response.Write("<br>OldValue " & key & ": " &
    > e.OldValues.Item(key))
    > Next
    >
    > For Each key In e.NewValues.Keys
    > Response.Write("<br>NewValue " & key & ": " &
    > e.NewValues.Item(key))
    > Next
    >
    > End Sub
    > =======================
    >
    > Hope helps. Thanks,
    >
    > Steven Cheng
    > Microsoft Online Support
    >
    > Get Secure! www.microsoft.com/security
    >
    >
    > --------------------
    > | Thread-Topic: DetailsView and ObjectDataSource - how to get updated object
    > | thread-index: AcXNxzuppqkjoBg/TQ+cRz+v5sT3OA==
    > | X-WBNR-Posting-Host: 209.137.235.2
    > | From: "=?Utf-8?B?SmltIEhhbW1vbmQ=?=" <>
    > | References: <>
    > <>
    > <>
    > <>
    > <>
    > <X#>
    > | Subject: RE: DetailsView and ObjectDataSource - how to get updated object
    > | Date: Mon, 10 Oct 2005 11:20:03 -0700
    > | Lines: 307
    > | Message-ID: <>
    > | MIME-Version: 1.0
    > | Content-Type: text/plain;
    > | charset="Utf-8"
    > | Content-Transfer-Encoding: 7bit
    > | X-Newsreader: Microsoft CDO for Windows 2000
    > | Content-Class: urn:content-classes:message
    > | Importance: normal
    > | Priority: normal
    > | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0
    > | Newsgroups: microsoft.public.dotnet.framework.aspnet
    > | NNTP-Posting-Host: TK2MSFTNGXA03.phx.gbl 10.40.2.250
    > | Path: TK2MSFTNGXA02.phx.gbl!TK2MSFTNGXA03.phx.gbl
    > | Xref: TK2MSFTNGXA02.phx.gbl
    > microsoft.public.dotnet.framework.aspnet:349765
    > | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
    > |
    > | Calling DataView1.UpdateItem(false) in a button click handler does cause
    > the
    > | data object's update method to be called; however, the properties of data
    > | object passed to the update method do not contain the current values on
    > the
    > | screen. (The DefaultMode is Edit.)
    > |
    > | "Steven Cheng[MSFT]" wrote:
    > |
    > | > Hi Jim,
    > | >
    > | > Thanks for your response.
    > | > yes, when using boundField with DefaultMode = EditMode, we can not use
    > | > Cell.Text because at that time , the field's value is stored in a
    > TextBox
    > | > inside the Cell. In other word, we also need to use FindControl in such
    > | > scenario. And currently the best choice is still utilizing the buildin
    > | > updating /updated events of the control. Also, we can programmatically
    > | > fire the
    > | > DetailsView's "ItemUpdating" event by calling the
    > DetailsView.UpdateItem()
    > | > method, we can call it as long as the DetailsView is in edit mode.
    > | >
    > | > So for your scenario, I think we can set the DetailsView's default mode
    > to
    > | > edit, use autogeneratedrows , then we can call DetailsView.UpdateItem
    > in
    > | > a certain postback button which is outside the detailsView control.
    > This
    > | > should be the best approach currently available. How do you think?
    > | >
    > | > #DetailsView.UpdateItem Method
    > | > http://msdn2.microsoft.com/en-us/library/ms155863(en-US,VS.80).aspx
    > | >
    > | > BTW, as for the the limitation you mentioned, I do agree that some of
    > them
    > | > are reasonable such as make programmatical update/edit... more
    > convenient
    > | > and provide a more easy to use inteface to access the binded data from
    > | > DetailsView (or other single databinding control as FormView). I'd
    > | > recommend you submit this feature request through MSWISH feedback
    > | > ().
    > | >
    > | > 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=?=" <>
    > | > | References: <>
    > | > <>
    > | > <>
    > | > <>
    > | > | Subject: RE: DetailsView and ObjectDataSource - how to get updated
    > object
    > | > | Date: Fri, 7 Oct 2005 12:53:09 -0700
    > | > | Lines: 223
    > | > | Message-ID: <>
    > | > | 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=?="
    > <>
    > | > | > | References: <>
    > | > | > <>
    > | > | > | Subject: RE: DetailsView and ObjectDataSource - how to get
    > updated
    > | > object
    > | > | > | Date: Thu, 6 Oct 2005 13:17:14 -0700
    > | > | > | Lines: 83
    > | > | > | Message-ID: <>
    > | > | > | 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
     
    =?Utf-8?B?SmltIEhhbW1vbmQ=?=, Oct 11, 2005
    #9
  10. 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=?=" <>
    | References: <>
    <>
    <>
    <>
    <>
    <X#>
    <>
    <NiuM$>
    | Subject: RE: DetailsView and ObjectDataSource - how to get updated object
    | Date: Tue, 11 Oct 2005 08:29:07 -0700
    | Lines: 313
    | Message-ID: <>
    | 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!TK2MSFTNGP08.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.DetailsViewUpdateEventArgs) Handles
    | > DetailsView1.ItemUpdating
    | > Response.Write("<br>DetailsView1_ItemUpdating " &
    | > DateTime.Now.Ticks)
    | >
    | > Dim key As String
    | >
    | > For Each key In e.Keys.Keys
    | > Response.Write("<br>Key " & key & ": " & e.Keys.Item(key))
    | > Next
    | >
    | > For Each key In e.OldValues.Keys
    | > Response.Write("<br>OldValue " & key & ": " &
    | > e.OldValues.Item(key))
    | > Next
    | >
    | > For Each key In e.NewValues.Keys
    | > Response.Write("<br>NewValue " & key & ": " &
    | > e.NewValues.Item(key))
    | > Next
    | >
    | > End Sub
    | > =======================
    | >
    | > Hope helps. Thanks,
    | >
    | > Steven Cheng
    | > Microsoft Online Support
    | >
    | > Get Secure! www.microsoft.com/security
    | >
    | >
    | > --------------------
    | > | Thread-Topic: DetailsView and ObjectDataSource - how to get updated
    object
    | > | thread-index: AcXNxzuppqkjoBg/TQ+cRz+v5sT3OA==
    | > | X-WBNR-Posting-Host: 209.137.235.2
    | > | From: "=?Utf-8?B?SmltIEhhbW1vbmQ=?=" <>
    | > | References: <>
    | > <>
    | > <>
    | > <>
    | > <>
    | > <X#>
    | > | Subject: RE: DetailsView and ObjectDataSource - how to get updated
    object
    | > | Date: Mon, 10 Oct 2005 11:20:03 -0700
    | > | Lines: 307
    | > | Message-ID: <>
    | > | MIME-Version: 1.0
    | > | Content-Type: text/plain;
    | > | charset="Utf-8"
    | > | Content-Transfer-Encoding: 7bit
    | > | X-Newsreader: Microsoft CDO for Windows 2000
    | > | Content-Class: urn:content-classes:message
    | > | Importance: normal
    | > | Priority: normal
    | > | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0
    | > | Newsgroups: microsoft.public.dotnet.framework.aspnet
    | > | NNTP-Posting-Host: TK2MSFTNGXA03.phx.gbl 10.40.2.250
    | > | Path: TK2MSFTNGXA02.phx.gbl!TK2MSFTNGXA03.phx.gbl
    | > | Xref: TK2MSFTNGXA02.phx.gbl
    | > microsoft.public.dotnet.framework.aspnet:349765
    | > | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
    | > |
    | > | Calling DataView1.UpdateItem(false) in a button click handler does
    cause
    | > the
    | > | data object's update method to be called; however, the properties of
    data
    | > | object passed to the update method do not contain the current values
    on
    | > the
    | > | screen. (The DefaultMode is Edit.)
    | > |
    | > | "Steven Cheng[MSFT]" wrote:
    | > |
    | > | > Hi Jim,
    | > | >
    | > | > Thanks for your response.
    | > | > yes, when using boundField with DefaultMode = EditMode, we can not
    use
    | > | > Cell.Text because at that time , the field's value is stored in a
    | > TextBox
    | > | > inside the Cell. In other word, we also need to use FindControl in
    such
    | > | > scenario. And currently the best choice is still utilizing the
    buildin
    | > | > updating /updated events of the control. Also, we can
    programmatically
    | > | > fire the
    | > | > DetailsView's "ItemUpdating" event by calling the
    | > DetailsView.UpdateItem()
    | > | > method, we can call it as long as the DetailsView is in edit
    mode.
    | > | >
    | > | > So for your scenario, I think we can set the DetailsView's default
    mode
    | > to
    | > | > edit, use autogeneratedrows , then we can call
    DetailsView.UpdateItem
    | > in
    | > | > a certain postback button which is outside the detailsView control.

    | > This
    | > | > should be the best approach currently available. How do you think?
    | > | >
    | > | > #DetailsView.UpdateItem Method
    | > | > http://msdn2.microsoft.com/en-us/library/ms155863(en-US,VS.80).aspx
    | > | >
    | > | > BTW, as for the the limitation you mentioned, I do agree that some
    of
    | > them
    | > | > are reasonable such as make programmatical update/edit... more
    | > convenient
    | > | > and provide a more easy to use inteface to access the binded data
    from
    | > | > DetailsView (or other single databinding control as FormView). I'd
    | > | > recommend you submit this feature request through MSWISH feedback
    | > | > ().
    | > | >
    | > | > 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=?="
    <>
    | > | > | References: <>
    | > | > <>
    | > | > <>
    | > | > <>
    | > | > | Subject: RE: DetailsView and ObjectDataSource - how to get
    updated
    | > object
    | > | > | Date: Fri, 7 Oct 2005 12:53:09 -0700
    | > | > | Lines: 223
    | > | > | Message-ID: <>
    | > | > | 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=?="
    | > <>
    | > | > | > | References:
    <>
    | > | > | > <>
    | > | > | > | Subject: RE: DetailsView and ObjectDataSource - how to get
    | > updated
    | > | > object
    | > | > | > | Date: Thu, 6 Oct 2005 13:17:14 -0700
    | > | > | > | Lines: 83
    | > | > | > | Message-ID:
    <>
    | > | > | > | 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
    |
     
    Steven Cheng[MSFT], Oct 12, 2005
    #10
  11. 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=?=" <>
    > | References: <>
    > <>
    > <>
    > <>
    > <>
    > <X#>
    > <>
    > <NiuM$>
    > | Subject: RE: DetailsView and ObjectDataSource - how to get updated object
    > | Date: Tue, 11 Oct 2005 08:29:07 -0700
    > | Lines: 313
    > | Message-ID: <>
    > | 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!TK2MSFTNGP08.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.DetailsViewUpdateEventArgs) Handles
    > | > DetailsView1.ItemUpdating
    > | > Response.Write("<br>DetailsView1_ItemUpdating " &
    > | > DateTime.Now.Ticks)
    > | >
    > | > Dim key As String
    > | >
    > | > For Each key In e.Keys.Keys
    > | > Response.Write("<br>Key " & key & ": " & e.Keys.Item(key))
    > | > Next
    > | >
    > | > For Each key In e.OldValues.Keys
    > | > Response.Write("<br>OldValue " & key & ": " &
    > | > e.OldValues.Item(key))
    > | > Next
    > | >
    > | > For Each key In e.NewValues.Keys
    > | > Response.Write("<br>NewValue " & key & ": " &
    > | > e.NewValues.Item(key))
    > | > Next
    > | >
    > | > End Sub
    > | > =======================
    > | >
    > | > Hope helps. Thanks,
    > | >
    > | > Steven Cheng
    > | > Microsoft Online Support
    > | >
    > | > Get Secure! www.microsoft.com/security
    > | >
    > | >
    > | > --------------------
    > | > | Thread-Topic: DetailsView and ObjectDataSource - how to get updated
    > object
    > | > | thread-index: AcXNxzuppqkjoBg/TQ+cRz+v5sT3OA==
    > | > | X-WBNR-Posting-Host: 209.137.235.2
    > | > | From: "=?Utf-8?B?SmltIEhhbW1vbmQ=?=" <>
    > | > | References: <>
    > | > <>
    > | > <>
    > | > <>
    > | > <>
    > | > <X#>
    > | > | Subject: RE: DetailsView and ObjectDataSource - how to get updated
    > object
    > | > | Date: Mon, 10 Oct 2005 11:20:03 -0700
    > | > | Lines: 307
    > | > | Message-ID: <>
    > | > | MIME-Version: 1.0
    > | > | Content-Type: text/plain;
    > | > | charset="Utf-8"
    > | > | Content-Transfer-Encoding: 7bit
    > | > | X-Newsreader: Microsoft CDO for Windows 2000
    > | > | Content-Class: urn:content-classes:message
    > | > | Importance: normal
    > | > | Priority: normal
    > | > | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0
    > | > | Newsgroups: microsoft.public.dotnet.framework.aspnet
    > | > | NNTP-Posting-Host: TK2MSFTNGXA03.phx.gbl 10.40.2.250
    > | > | Path: TK2MSFTNGXA02.phx.gbl!TK2MSFTNGXA03.phx.gbl
    > | > | Xref: TK2MSFTNGXA02.phx.gbl
    > | > microsoft.public.dotnet.framework.aspnet:349765
    > | > | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
    > | > |
    > | > | Calling DataView1.UpdateItem(false) in a button click handler does
    > cause
    > | > the
    > | > | data object's update method to be called; however, the properties of
    > data
    > | > | object passed to the update method do not contain the current values
    > on
    > | > the
    > | > | screen. (The DefaultMode is Edit.)
    > | > |
    > | > | "Steven Cheng[MSFT]" wrote:
    > | > |
    > | > | > Hi Jim,
    > | > | >
    > | > | > Thanks for your response.
    > | > | > yes, when using boundField with DefaultMode = EditMode, we can not
    > use
    > | > | > Cell.Text because at that time , the field's value is stored in a
    > | > TextBox
    > | > | > inside the Cell. In other word, we also need to use FindControl in
    > such
    > | > | > scenario. And currently the best choice is still utilizing the
    > buildin
    > | > | > updating /updated events of the control. Also, we can
    > programmatically
    > | > | > fire the
    > | > | > DetailsView's "ItemUpdating" event by calling the
    > | > DetailsView.UpdateItem()
    > | > | > method, we can call it as long as the DetailsView is in edit
    > mode.
    > | > | >
    > | > | > So for your scenario, I think we can set the DetailsView's default
    > mode
    > | > to
    > | > | > edit, use autogeneratedrows , then we can call
    > DetailsView.UpdateItem
    > | > in
    > | > | > a certain postback button which is outside the detailsView control.
    >
    > | > This
    > | > | > should be the best approach currently available. How do you think?
    > | > | >
    > | > | > #DetailsView.UpdateItem Method
    > | > | > http://msdn2.microsoft.com/en-us/library/ms155863(en-US,VS.80).aspx
    > | > | >
    > | > | > BTW, as for the the limitation you mentioned, I do agree that some
    > of
    > | > them
    > | > | > are reasonable such as make programmatical update/edit... more
    > | > convenient
    > | > | > and provide a more easy to use inteface to access the binded data
    > from
    > | > | > DetailsView (or other single databinding control as FormView). I'd
    > | > | > recommend you submit this feature request through MSWISH feedback
    > | > | > ().
    > | > | >
    > | > | > 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=?="
    > <>
    > | > | > | References: <>
    > | > | > <>
    > | > | > <>
    > | > | > <>
    > | > | > | Subject: RE: DetailsView and ObjectDataSource - how to get
    > updated
    > | > object
    > | > | > | Date: Fri, 7 Oct 2005 12:53:09 -0700
    > | > | > | Lines: 223
    > | > | > | Message-ID: <>
    > | > | > | 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
     
    =?Utf-8?B?SmltIEhhbW1vbmQ=?=, Oct 13, 2005
    #11
  12. 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=?=" <>
    | References: <>
    <>
    <>
    <>
    <>
    <X#>
    <>
    <NiuM$>
    <>
    <>
    | Subject: RE: DetailsView and ObjectDataSource - how to get updated object
    | Date: Wed, 12 Oct 2005 16:09:02 -0700
    | Lines: 320
    | Message-ID: <>
    | 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=?=" <>
    | > | References: <>
    | > <>
    | > <>
    | > <>
    | > <>
    | > <X#>
    | > <>
    | > <NiuM$>
    | > | Subject: RE: DetailsView and ObjectDataSource - how to get updated
    object
    | > | Date: Tue, 11 Oct 2005 08:29:07 -0700
    | > | Lines: 313
    | > | Message-ID: <>
    | > | 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!TK2MSFTNGP08.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.DetailsViewUpdateEventArgs) Handles
    | > | > DetailsView1.ItemUpdating
    | > | > Response.Write("<br>DetailsView1_ItemUpdating " &
    | > | > DateTime.Now.Ticks)
    | > | >
    | > | > Dim key As String
    | > | >
    | > | > For Each key In e.Keys.Keys
    | > | > Response.Write("<br>Key " & key & ": " &
    e.Keys.Item(key))
    | > | > Next
    | > | >
    | > | > For Each key In e.OldValues.Keys
    | > | > Response.Write("<br>OldValue " & key & ": " &
    | > | > e.OldValues.Item(key))
    | > | > Next
    | > | >
    | > | > For Each key In e.NewValues.Keys
    | > | > Response.Write("<br>NewValue " & key & ": " &
    | > | > e.NewValues.Item(key))
    | > | > Next
    | > | >
    | > | > End Sub
    | > | > =======================
    | > | >
    | > | > Hope helps. Thanks,
    | > | >
    | > | > Steven Cheng
    | > | > Microsoft Online Support
    | > | >
    | > | > Get Secure! www.microsoft.com/security
    | > | >
    | > | >
    | > | > --------------------
    | > | > | Thread-Topic: DetailsView and ObjectDataSource - how to get
    updated
    | > object
    | > | > | thread-index: AcXNxzuppqkjoBg/TQ+cRz+v5sT3OA==
    | > | > | X-WBNR-Posting-Host: 209.137.235.2
    | > | > | From: "=?Utf-8?B?SmltIEhhbW1vbmQ=?="
    <>
    | > | > | References: <>
    | > | > <>
    | > | > <>
    | > | > <>
    | > | > <>
    | > | > <X#>
    | > | > | Subject: RE: DetailsView and ObjectDataSource - how to get
    updated
    | > object
    | > | > | Date: Mon, 10 Oct 2005 11:20:03 -0700
    | > | > | Lines: 307
    | > | > | Message-ID: <>
    | > | > | MIME-Version: 1.0
    | > | > | Content-Type: text/plain;
    | > | > | charset="Utf-8"
    | > | > | Content-Transfer-Encoding: 7bit
    | > | > | X-Newsreader: Microsoft CDO for Windows 2000
    | > | > | Content-Class: urn:content-classes:message
    | > | > | Importance: normal
    | > | > | Priority: normal
    | > | > | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0
    | > | > | Newsgroups: microsoft.public.dotnet.framework.aspnet
    | > | > | NNTP-Posting-Host: TK2MSFTNGXA03.phx.gbl 10.40.2.250
    | > | > | Path: TK2MSFTNGXA02.phx.gbl!TK2MSFTNGXA03.phx.gbl
    | > | > | Xref: TK2MSFTNGXA02.phx.gbl
    | > | > microsoft.public.dotnet.framework.aspnet:349765
    | > | > | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
    | > | > |
    | > | > | Calling DataView1.UpdateItem(false) in a button click handler
    does
    | > cause
    | > | > the
    | > | > | data object's update method to be called; however, the properties
    of
    | > data
    | > | > | object passed to the update method do not contain the current
    values
    | > on
    | > | > the
    | > | > | screen. (The DefaultMode is Edit.)
    | > | > |
    | > | > | "Steven Cheng[MSFT]" wrote:
    | > | > |
    | > | > | > Hi Jim,
    | > | > | >
    | > | > | > Thanks for your response.
    | > | > | > yes, when using boundField with DefaultMode = EditMode, we can
    not
    | > use
    | > | > | > Cell.Text because at that time , the field's value is stored in
    a
    | > | > TextBox
    | > | > | > inside the Cell. In other word, we also need to use FindControl
    in
    | > such
    | > | > | > scenario. And currently the best choice is still utilizing the
    | > buildin
    | > | > | > updating /updated events of the control. Also, we can
    | > programmatically
    | > | > | > fire the
    | > | > | > DetailsView's "ItemUpdating" event by calling the
    | > | > DetailsView.UpdateItem()
    | > | > | > method, we can call it as long as the DetailsView is in edit
    | > mode.
    | > | > | >
    | > | > | > So for your scenario, I think we can set the DetailsView's
    default
    | > mode
    | > | > to
    | > | > | > edit, use autogeneratedrows , then we can call
    | > DetailsView.UpdateItem
    | > | > in
    | > | > | > a certain postback button which is outside the detailsView
    control.
    | >
    | > | > This
    | > | > | > should be the best approach currently available. How do you
    think?
    | > | > | >
    | > | > | > #DetailsView.UpdateItem Method
    | > | > | >
    http://msdn2.microsoft.com/en-us/library/ms155863(en-US,VS.80).aspx
    | > | > | >
    | > | > | > BTW, as for the the limitation you mentioned, I do agree that
    some
    | > of
    | > | > them
    | > | > | > are reasonable such as make programmatical update/edit... more
    | > | > convenient
    | > | > | > and provide a more easy to use inteface to access the binded
    data
    | > from
    | > | > | > DetailsView (or other single databinding control as FormView).
    I'd
    | > | > | > recommend you submit this feature request through MSWISH
    feedback
    | > | > | > ().
    | > | > | >
    | > | > | > 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=?="
    | > <>
    | > | > | > | References:
    <>
    | > | > | > <>
    | > | > | > <>
    | > | > | > <>
    | > | > | > | Subject: RE: DetailsView and ObjectDataSource - how to get
    | > updated
    | > | > object
    | > | > | > | Date: Fri, 7 Oct 2005 12:53:09 -0700
    | > | > | > | Lines: 223
    | > | > | > | Message-ID:
    <>
    | > | > | > | 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
    |
     
    Steven Cheng[MSFT], Oct 13, 2005
    #12
  13. thanks, but I have resolved this issue and posted the solution at:

    http://codeproject.com/useritems/ObjectDataSource_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=?=" <>
    > | References: <>
    > <>
    > <>
    > <>
    > <>
    > <X#>
    > <>
    > <NiuM$>
    > <>
    > <>
    > | Subject: RE: DetailsView and ObjectDataSource - how to get updated object
    > | Date: Wed, 12 Oct 2005 16:09:02 -0700
    > | Lines: 320
    > | Message-ID: <>
    > | 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=?=" <>
    > | > | References: <>
    > | > <>
    > | > <>
    > | > <>
    > | > <>
    > | > <X#>
    > | > <>
    > | > <NiuM$>
    > | > | Subject: RE: DetailsView and ObjectDataSource - how to get updated
    > object
    > | > | Date: Tue, 11 Oct 2005 08:29:07 -0700
    > | > | Lines: 313
    > | > | Message-ID: <>
    > | > | 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!TK2MSFTNGP08.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.DetailsViewUpdateEventArgs) Handles
    > | > | > DetailsView1.ItemUpdating
    > | > | > Response.Write("<br>DetailsView1_ItemUpdating " &
    > | > | > DateTime.Now.Ticks)
    > | > | >
    > | > | > Dim key As String
    > | > | >
    > | > | > For Each key In e.Keys.Keys
    > | > | > Response.Write("<br>Key " & key & ": " &
    > e.Keys.Item(key))
    > | > | > Next
    > | > | >
    > | > | > For Each key In e.OldValues.Keys
    > | > | > Response.Write("<br>OldValue " & key & ": " &
    > | > | > e.OldValues.Item(key))
    > | > | > Next
    > | > | >
    > | > | > For Each key In e.NewValues.Keys
    > | > | > Response.Write("<br>NewValue " & key & ": " &
    > | > | > e.NewValues.Item(key))
    > | > | > Next
    > | > | >
    > | > | > End Sub
    > | > | > =======================
    > | > | >
    > | > | > Hope helps. Thanks,
    > | > | >
    > | > | > Steven Cheng
    > | > | > Microsoft Online Support
    > | > | >
    > | > | > Get Secure! www.microsoft.com/security
    > | > | >
    > | > | >
    > | > | > --------------------
    > | > | > | Thread-Topic: DetailsView and ObjectDataSource - how to get
    > updated
    > | > object
    > | > | > | thread-index: AcXNxzuppqkjoBg/TQ+cRz+v5sT3OA==
    > | > | > | X-WBNR-Posting-Host: 209.137.235.2
    > | > | > | From: "=?Utf-8?B?SmltIEhhbW1vbmQ=?="
    > <>
    > | > | > | References: <>
    > | > | > <>
    > | > | > <>
    > | > | > <>
    > | > | > <>
    > | > | > <X#>
    > | > | > | Subject: RE: DetailsView and ObjectDataSource - how to get
    > updated
    > | > object
    > | > | > | Date: Mon, 10 Oct 2005 11:20:03 -0700
    > | > | > | Lines: 307
    > | > | > | Message-ID: <>
    > | > | > | 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
     
    =?Utf-8?B?SmltIEhhbW1vbmQ=?=, Oct 18, 2005
    #13
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Spotnick
    Replies:
    0
    Views:
    1,584
    Spotnick
    Jan 21, 2006
  2. J055
    Replies:
    1
    Views:
    1,931
    Steven Cheng[MSFT]
    Apr 5, 2006
  3. =?Utf-8?B?RGVuaXMgU29oZXQ=?=

    Error with ObjectDataSource and DetailsView - conversion error

    =?Utf-8?B?RGVuaXMgU29oZXQ=?=, Mar 28, 2007, in forum: ASP .Net
    Replies:
    0
    Views:
    449
    =?Utf-8?B?RGVuaXMgU29oZXQ=?=
    Mar 28, 2007
  4. Bill Gower

    DetailsView and ObjectDataSource

    Bill Gower, Aug 30, 2007, in forum: ASP .Net
    Replies:
    0
    Views:
    385
    Bill Gower
    Aug 30, 2007
  5. Dmitry Korolyov

    Datagrid not updated during delete, but updated during insert and update

    Dmitry Korolyov, Sep 22, 2003, in forum: ASP .Net Datagrid Control
    Replies:
    0
    Views:
    439
    Dmitry Korolyov
    Sep 22, 2003
Loading...

Share This Page