Hi again,
Here's what you need to do to make updates work.
1. Open Products.aspx from the Management folder.
2. Open the GridView's Fields collection and add a HyperLinkField with an Edit link. You should end up with something like this:
Code:
<asp:HyperLinkField DataNavigateUrlFields="Id" Text="Edit"
DataNavigateUrlFormatString="AddProduct.aspx?Id={0}" />
3. Open up AddProduct.aspx and add the following code to a Page_Load handler:
Code:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Code:
If Request.QueryString.Get("Id") IsNot Nothing Then
FormView1.DefaultMode = FormViewMode.Edit
End If
End Sub
4. Switch to Design View and run the config wizard for odsProducts. Choose InsertProduct(Product theProduct) as the UPDATE method (identical to the existing INSERT method). Choose a QueryString parameter called Id as the source for the theProductId parameter on the "Define Parameters" screen of the wizard.
5. Set the DataKeyNames of the FormView to Id.
6. Create an EditItemTemplate for the FormView (copy the InsertItemTemplate or create your own). Make sure you change the Insert button to an Update button.
That's pretty much it. The business and data access layers will be able to determine whether you are inserting or update an item and act accordingly.
Of course there is still some work to be done with the EditItemTemplate. You need to handle the Updating and Updated events to deal with the uploaded / changed images. However, this post should get you in the right direction....
Personally, I don't like th FormView in situations like this too much. You need *a lot* of markup an duplicate it in InsertItemTemplate and EditItemTemplate. You may want to take a look at the CMS chapter that shows an easier solution to dealing with inserts and updates.
Hope this helps,
Imar
---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of
ASP.NET 2.0 Instant Results and
Beginning Dreamweaver MX / MX 2004
Want to be my colleague? Then check out this post.