formview with a dataset - cannot modify records

D

deftone

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
 
D

deftone

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
 
D

deftone

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
 
D

deftone

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top