Retain Values in FormView Control after Item has been Inserted

Recently someone asked me that how can I retain the values in the controls inside the FormView control after the insert operation. I thought a simple EnableViewState = "true" would do the trick but it was much complicated then that. According to some postings you can easily enable to retain the values in the controls by using a e.KeepInInsertMode = true; inside the FormView item inserted event. Unfortunaltely the technique did not work and for some reason the FormView control was always clearing out the controls inside it.

The workaround I found was to code inside the FormView item created event. Here is my FormView1_ItemCreated event which retains the values inside the FormView control.

protected void FormView1_ItemCreated(object sender, EventArgs e)
    {
        TextBox tFirstName = (FormView1.Row.FindControl("FirstNameTextBox")
        
as TextBox);
        TextBox tLastName = (FormView1.Row.FindControl("LastNameTextBox")
        
as TextBox);

        tFirstName.Text = Session["FirstName"] 
as String;
        tLastName.Text = Session["LastName"] 
as String; 
    }

I had values stored inside the Session variable but you can use any state medium you like.

powered by IMHO 1.3

Print | posted @ Thursday, July 27, 2006 5:57 PM

Twitter