formview with a dataset - cannot modify records

Discussion in 'ASP .Net' started by deftone, Sep 11, 2007.

  1. deftone

    deftone Guest

    I am trying to do something that to me sounds simple, but yet I have
    struggled over it for several days. My goal is to use a formview to
    edit a record. The datasource of the formview is a simple dataset with
    1 table and several records. I have no problem getting the data to
    display in the form. When I make an edit and submit, the formview
    will postback and displays the updates within the fields, however the
    ItemUpdating sub is telling me it found no changes and has nothing to
    update the dataset with. I have broken down the code below. Any help
    would be greatly appreciated.


    The formview has a single DataKeyNames set to it. It is not being
    databound after a postback.

    --- submit button
    <asp:ImageButton ID="btnRecordSave" runat="server" ImageUrl="~/Images/
    btn_save.png" />


    --- formview
    <asp:FormView ID="fvDetails" runat="server">
    <EditItemTemplate> ...bunch of bound input fields </
    EditItemTemplate>
    </asp:FormView>


    --- handle submit click
    Private Sub btnRecordSave_Click(ByVal sender As Object, ByVal e As
    System.Web.UI.ImageClickEventArgs) Handles btnRecordSave.Click
    fvDetails.UpdateItem(True)
    End Sub


    --- formview item updating sub
    Private Sub fvDetails_ItemUpdating(ByVal sender As Object, ByVal e As
    System.Web.UI.WebControls.FormViewUpdateEventArgs) Handles
    fvDetails.ItemUpdating

    lblPageInfo.Text &= "<br>oldvalues=" & e.OldValues.Count
    lblPageInfo.Text &= "<br>keys=" & e.Keys.Count
    lblPageInfo.Text &= "<br>newvalues=" & e.NewValues.Count

    End Sub
    deftone, Sep 11, 2007
    #1
    1. Advertising

  2. deftone

    deftone Guest

    Also, I did not mention that my itemupdating sub has been altered to
    just display the count of the changed fields. It is returning zero for
    each one

    lblPageInfo.Text &= "<br>oldvalues=" & e.OldValues.Count
    lblPageInfo.Text &= "<br>keys=" & e.Keys.Count
    lblPageInfo.Text &= "<br>newvalues=" & e.NewValues.Count

    results in

    oldvalues=0
    keys=0
    newvalues=0
    deftone, Sep 11, 2007
    #2
    1. Advertising

  3. deftone

    deftone Guest

    I am answering my question here after someone emailed me about it....

    Originally i was trying to use a dataset on the formview. I would set
    fv.datasource = ds. I found that if you do that, the form will not
    automatically fill the newvalues and oldvalues when running
    fv_ItemUpdating.

    So the alternate approach is to create a datasource control, in my
    case an ObjectDataSource named dbSource. Then use that to set the
    fv.DataSourceID = dbSource.ID. Doing this, everything worked the way
    you would expect it to. It automatically filled in the new and old
    values.

    So, in short...
    fv.DataSource = dataset, etc ----> you shit wont work as you would
    expect.
    fv.DataSourceID = DataSource.id ----> this will work
    deftone, Oct 31, 2007
    #3
  4. deftone

    deftone Guest

    I am answering my question here after someone emailed me about it....

    Originally i was trying to use a dataset on the formview. I would set
    fv.datasource = ds. I found that if you do that, the form will not
    automatically fill the newvalues and oldvalues when running
    fv_ItemUpdating.

    So the alternate approach is to create a datasource control, in my
    case an ObjectDataSource named dbSource. Then use that to set the
    fv.DataSourceID = dbSource.ID. Doing this, everything worked the way
    you would expect it to. It automatically filled in the new and old
    values.

    So, in short...
    fv.DataSource = dataset, etc ----> your shit wont work as you would
    expect.
    fv.DataSourceID = DataSource.id ----> this will work
    deftone, Oct 31, 2007
    #4
    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. Luke Airig
    Replies:
    0
    Views:
    771
    Luke Airig
    Dec 31, 2003
  2. Chris

    Formview within Formview

    Chris, May 19, 2007, in forum: ASP .Net
    Replies:
    0
    Views:
    503
    Chris
    May 19, 2007
  3. Jay Pondy
    Replies:
    0
    Views:
    715
    Jay Pondy
    Apr 4, 2008
  4. Dan

    Delete records or update records

    Dan, May 10, 2004, in forum: ASP General
    Replies:
    1
    Views:
    451
    Ray at
    May 10, 2004
  5. Replies:
    3
    Views:
    640
    Anthony Jones
    Nov 2, 2006
Loading...

Share This Page