Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / October 2007

Tip: Looking for answers? Try searching our database.

formview with a dataset - cannot modify records

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
deftone - 11 Sep 2007 17:04 GMT
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 - 11 Sep 2007 17:08 GMT
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 - 31 Oct 2007 19:22 GMT
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 sh.t wont work as you would
expect.
fv.DataSourceID = DataSource.id ----> this will work
deftone - 31 Oct 2007 19:22 GMT
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 sh.t wont work as you would
expect.
fv.DataSourceID = DataSource.id ----> this will work

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.