Formview: Displaying inserted data?

Last post 08-28-2008 1:19 PM by mtv. 18 replies.

Sort Posts:

  • Formview: Displaying inserted data?

    12-12-2006, 8:55 AM

    Hi,

    This probably has been asked before but I haven't found an answer ...

    So again then: I've created a FormView with Insert mode as default. The form works, the data gets saved. And now I'd like to display the data that just got entered in a read-only FormView so the user can print it out. How would I do that?

    I tried it with this:

    Protected Sub FormView1_ItemInserted(ByVal sender As Object, ByVal e As FormViewInsertedEventArgs)

            If e.Exception Is Nothing Then
       
                If e.AffectedRows = 1 Then
         
                    FormView1.ChangeMode(FormViewMode.ReadOnly)
                    FormView1.DataBind()

                    MessageLabel.Text = "Record inserted successfully."
         
                Else
         
                    MessageLabel.Text = "An error occurred during the insert operation."
           
                    e.KeepInInsertMode = True
         
                End If
       
            Else
       
            MessageLabel.Text = e.Exception.Message
         
                e.ExceptionHandled = True
                e.KeepInInsertMode = True
       
            End If
           
        End Sub

    For some reason the text of the MessageLabel gets displayed correctly but the FormView remains in Insert mode.

    Any ideas what went wrong?

    Thanks a lot!
     

    Filed under:
  • Re: Formview: Displaying inserted data?

    12-13-2006, 1:55 AM
    • Loading...
    • rexlin
    • Joined on 07-17-2006, 8:43 AM
    • Posts 1,751

    Hi, Subliminal Void :

     Try to put you changeMode code into Prerender event.



    Best Regards,
    __________________________________________________
    Sincerely,
    Rex Lin
    Microsoft Online Community Support

    This posting is provided "AS IS" with on warranties, and confers no rights.
  • Re: Formview: Displaying inserted data?

    12-13-2006, 3:04 AM
    But wouldn't the Mode then always be changed?? And not only after an item was inserted?
  • Re: Formview: Displaying inserted data?

    12-13-2006, 3:40 AM
    • Loading...
    • rexlin
    • Joined on 07-17-2006, 8:43 AM
    • Posts 1,751

    if (FormView1.CurrentMode == FormViewMode.Insert)

    {//put the changemode here

    }



    Best Regards,
    __________________________________________________
    Sincerely,
    Rex Lin
    Microsoft Online Community Support

    This posting is provided "AS IS" with on warranties, and confers no rights.
  • Re: Formview: Displaying inserted data?

    12-13-2006, 4:25 AM

    Thanks for answering, but that creates the same problem:

    The page then gets ALWAYS displayed in Read-Only mode instead of only AFTER INSERTING the data.

    Again:

    Protected Sub FormView1_ItemInserted(ByVal sender As Object, ByVal e As FormViewInsertedEventArgs)
       
                    FormView1.ChangeMode(FormViewMode.ReadOnly)
                    FormView1.DataBind()

                    MessageLabel.Text = "Record inserted successfully."
             
     End Sub

     

    The MessageLabel.Text command gets executed correctly. But not the two commands above it.

    What I need, and this has to be possible!?, is to display the data I've just inserted via FormView.

    Any help is greatly appreciated,

    Jerome 

  • Re: Formview: Displaying inserted data?

    02-13-2007, 4:05 AM

    I'm still faced with the same problem and I'd like to know how to do this at last ...

    Any new ideas? Why does it show the label but not change the mode?

    Thanks a lot. 

  • Re: Formview: Displaying inserted data?

    02-13-2007, 7:04 PM
    • Loading...
    • Savitha Rao
    • Joined on 02-13-2007, 11:42 PM
    • Posts 2

    Write a button click event for new link button, which is present in the insert mode of the FormView Control - as below :

    protected

    void New_Click(object sender, EventArgs e)

    {

    // Save the details and change the mode back to read only.

    //Call Insert method here

    FormView1.ChangeMode(

    FormViewMode.ReadOnly);

    FormView1.Databind( );

  • Re: Formview: Displaying inserted data?

    02-13-2007, 8:25 PM

    I'm not sure here, but try calling dataind() before switching modes.

    FormView1.DataBind() 
    FormView1.ChangeMode(FormViewMode.ReadOnly)
    MessageLabel.Text = "Record inserted successfully."

  • Re: Formview: Displaying inserted data?

    03-01-2007, 10:55 PM
    • Loading...
    • OWEN ZHANG
    • Joined on 11-16-2006, 12:47 AM
    • China
    • Posts 37
    I got the same trouble. I think that the page actually reload after insert button clicked, so we should changemode in the pageload event.
  • Re: Formview: Displaying inserted data?

    04-12-2007, 7:47 PM
    Answer
    • Loading...
    • Savitha Rao
    • Joined on 02-13-2007, 11:42 PM
    • Posts 2

    I had the same problem. I could resolve this issue by following code:

    Write a button click event for "Insert" Link button present in the Insert Template of the Formview control :

    protected void Insert_Click(object sender, EventArs e)

    {

        //Call your Insert method 

        FormView1.ChangeMode(FormViewMode.Readonly);

        FormView1.DataBind();

    It worked fine for me!!  

     

  • Re: Formview: Displaying inserted data?

    05-24-2007, 1:07 PM
    • Loading...
    • aspnetpro
    • Joined on 04-13-2007, 11:19 PM
    • Posts 2

    I'm also facing the problem of displaying an inserted record using FormView.

    The problem occurs when there is at least one record already in the database table. After I click on the Insert button, the record is saved but is not displayed. The other record in the database is displayed instead. I will need to click on the paging link to retrieve the new record. This can be confusing to a user.

    I've tried all the suggested solutions mentioned in this post but none works for me.

    Has anyone else found a workable solution?

    Thanks.

     

    Filed under:
  • Re: Formview: Displaying inserted data?

    06-06-2007, 4:10 PM
    • Loading...
    • Jeewai
    • Joined on 10-06-2005, 6:32 AM
    • Posts 43

     

    I have been searching for a solution in the forum but there's none available. After an insert on a formview, how do you ensure that same page is displayed with the newly inserted data and not another page. In other words, how do you keep the paging to the current state? I gleaned the following bits of code but as a total newbie, not sure if it's related. 

    Any help would be terrific.

    Thanks

    Jeewai

     

    public int CurrentPage
          {
             get
             {
                // look for current page in ViewState
                object o = this.ViewState["_CurrentPage"];
                if (o == null)
                   return 0;   // default to showing the first page
                else
                   return (int) o;
             }

             set
             {
                this.ViewState["_CurrentPage"] = value;
             }
          }
     

     

     

  • Re: Formview: Displaying inserted data?

    06-14-2007, 9:56 PM
    • Loading...
    • hclouston
    • Joined on 06-15-2007, 1:52 AM
    • Posts 1

    I was having the same issue as this, I seem to have got around it by setting the default state of the formview to ReadOnly, then in the pageload included this code:

    if (!IsPostBack)
       {
           this.FormView1.ChangeMode(FormViewMode.Insert);
       }

     

     

  • Re: Formview: Displaying inserted data?

    06-18-2007, 4:02 PM
    • Loading...
    • Jeewai
    • Joined on 10-06-2005, 6:32 AM
    • Posts 43

    OK, Having the formview in insert mode by default and then changing automatically on read mode after an insert is quite easy and was well explained on one of the previous post on this thread:

    <script runat="server">
    Sub
    Page_Load()
    If Not IsPostBack Then
    If FormView1.DataItemCount = 0 Then
    FormView1.ChangeMode(FormViewMode.Insert)
    End If
    End If
    End Sub 'Page_Load

     

    Protected Sub InsertButton_Click(ByVal sender As Object, ByVal e As System.EventArgs)
    FormView1.DataBind()
    FormView1.ChangeMode(FormViewMode.ReadOnly)
    End Sub
    </
    script>

    Now the hic is that let's say I'm creating a new record (7) on my formview, when I hit the insert button, the form INVARIABLY return to record 1 and display in read mode (as per the code above). I want to be able to display the newly inserted record (which shoud be paging 7 )

    Can you guys give me a lead, in VB.net preferrably. Should I use the this.  attribute to refer to the new page I've been inserting

    Thanks for clarifying

     

     

  • Re: Formview: Displaying inserted data?

    07-05-2007, 11:15 AM
    • Loading...
    • sansie
    • Joined on 03-16-2007, 3:42 PM
    • Posts 14

    Hi, Did anyone solve this in VB, I'm also looking for an answer to this!

Page 1 of 2 (19 items) 1 2 Next >