Wrox Programmer Forums
|
BOOK: ASP.NET 2.0 Instant Results ISBN: 978-0-471-74951-6
This is the forum to discuss the Wrox book ASP.NET 2.0 Instant Results by Imar Spaanjaars, Paul Wilton, Shawn Livermore; ISBN: 9780471749516
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: ASP.NET 2.0 Instant Results ISBN: 978-0-471-74951-6 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 4th, 2008, 07:35 PM
Authorized User
 
Join Date: Oct 2007
Posts: 29
Thanks: 0
Thanked 0 Times in 0 Posts
Default formview

Hello,

Any help with this issue would be greatly appreciated. I can submit my update but I can't uppate my formview and then resubmit. I can't be only person having this issue.

 
Old January 4th, 2008, 07:58 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi there,

Sorry for the late replies; have been quiet busy for the past couple of days.

Can you define "update my formview"? Do you get an error? If so, what error do you get?

For some ideas on implementing updates, you may also want to take a look at other chapters like the CMS chapter.

I noticed a few other threads you started here, but they all deal with the same subject, right?

P.S. Might take a while before I can reply to any of your replies; it's past midnight here....

Cheers,

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.
 
Old January 4th, 2008, 08:21 PM
Authorized User
 
Join Date: Oct 2007
Posts: 29
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Imar,

My issues seems to be that I'm trying to pull the data back into my FormView and have the oppurtunity to change the data in the product table and once that is completed have the ability to update the data in that table. Where I am struggling is when I pull the data from the database then I can't update it or if I change my code I can update the data but I can't pull it into the form.

The reall issue I feel I'm having is that I have that date that I want in page load. I can see it when I run it in debug but I can't get it to popuate the formview so I can edit it and then resubmit the data as an update.

Please help.

Thanks

 
Old January 4th, 2008, 08:28 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

I must be thick today but I am having some problems understanding what you are saying.
Quote:
quote:Where I am struggling is when I pull the data from the database then I can't update it or if I change my code I can update the data but I can't pull it into the form.
What do you mean with "pull the data from the database then I can't update it"? Is the FormView not in Update mode? And what do you mean with "if I change my code I can update the data but I can't pull it into the form".
Quote:
quote:The reall issue I feel I'm having is that I have that date that I want in page load.
What date are you referring to? Does the Product class have a Date property? Also, where are you seeing this data in the debugger? When it comes from the database or when it comes from a Web Form on postback?

All in all, I need a *much* better description of your problems. Did you look at other chapters using a FormView to handle updates so you are comfortable with the general principle that drives them before you start with this?

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.
 
Old January 4th, 2008, 08:52 PM
Authorized User
 
Join Date: Oct 2007
Posts: 29
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Ok sorry for the confusion.

What I am trying to do is have the ability to update a product from the product table from chapter 9. So what I did was add an edit button from the Products page that redirects to an EditProduct page with the productid. What I wanted to do was on page load pupulate the formview that was used in AddProducts (I copied this code to the edit products page) so I could edit the product and then choose the update button and pass in all of the fields from the add products page along with the product id which would force and update instead of an insert. In the code and sql proc is says if you send in a product id it will do an update instead of an insert. So I used that code and in the sql proc I added a where id = @id so keep it to one product at time. Please let me know if you need me to post any code to make this any clearer.

 
Old January 5th, 2008, 06:44 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

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.





Similar Threads
Thread Thread Starter Forum Replies Last Post
FormView Control lokraj ASP.NET 2.0 Basics 0 September 11th, 2007 08:51 AM
Formview with ObjectDataSource rturner003 ASP.NET 2.0 Professional 3 November 1st, 2006 06:17 AM
Inserting in two formview shahzadgodil ASP.NET 2.0 Professional 2 October 18th, 2006 11:33 AM
formview please urgent help jameee ASP.NET 2.0 Professional 2 September 15th, 2006 05:18 PM
FormView and PostBackURL timeware ASP.NET 2.0 Professional 1 August 11th, 2006 10:22 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.