go from insert view to edit view in a formview after an insert is made.

Posted on 2007-07-20
Last Modified: 2009-03-23
I want to have the user enter their data into the "insert" portion of a formview, click the insert button and have the system save the info, then return the user to the edit mode.

You'd think this would be pretty standard....  

I figured there must be a better way to do this than writing a procedure to pull the identity.  Isn't there some fancy dotnet option?  Somewhere I saw someone using a select @@IDENTITY statement after the sql statement used on the insert option of the sql datasource.

Question by:Danielcmorris
    LVL 16

    Accepted Solution

    I would say what you want to do is create a stored procedure that has an output parameter to hold the inserted id on completion of the insert. When creating this procedure, you should also use "Scope_Identity()" instead of @@IDENTITY when using SQL Server. Once you have the sql stored procedure setup to fill the output variable, in your form view's ItemInserted event, retrieve this parameters value from your sql data source for the id and then use the formview's changemode() method to put the formview in edit mode.
    LVL 4

    Author Comment

    That's pretty much what I've been doing.  I just thought, since microsoft has gone soooo far out of it's way to make all the datacode for their data-objects into the "HTML" section of the page rather than the coded section, Perhaps they had built in a feature that would automatically do this for me.

    To be honest, I am really not all that big a fan of this .net stuff.  I really liked old fashioned asp.  Other than the debugging features of .net, it's really a bit of a pain.  I had assumed that "FormView", being the primary data form, would have a billion features built in, but I'm discovering that it is a LOT easier to write the code with a bunch of text boxes and just assign values from code.  It would certainly be a lot easier than writing the exact same form for INSERT as EDIT, where you've got to change both if your client wants a change.

    I think I'm just going to ditch FormView altogether unless there is some feature that I'm not missing.
    LVL 4

    Author Comment

     "not missing" --- um, I meant, "not getting"

    Expert Comment

    Daniel, I wish to do what you are talking about here, but I want to use a formview.  I understand how to do the stored procedure.  HOWEVER, I do not understand how to retrieve the parameter in the ItemInserted event as TSmooth states above.  Would you mind posting the code to retrieve the parameter??

    Thanks, Mark
    LVL 4

    Author Comment

    Mark,  I'll tell you what I did:

    I inserted the record.  Then:
    select max(contactid) from contacts


    I'm used to using SQL Server and I just got tired of trying to get MS Access to work with @@IDENTITY and scope... etc...  The system is only used by about 10 people and I wasn't going to spend any more time on it.

    Featured Post

    Why You Should Analyze Threat Actor TTPs

    After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

    Join & Write a Comment

    This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
    Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
    To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
    In this sixth video of the Xpdf series, we discuss and demonstrate the PDFtoPNG utility, which converts a multi-page PDF file to separate color, grayscale, or monochrome PNG files, creating one PNG file for each page in the PDF. It does this via a c…

    755 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    22 Experts available now in Live!

    Get 1:1 Help Now