How to pass values between FormViews ?
-
I want to pass a value from one formview to a second, FormView1 to FormView2. I start with FormView1 and insert a record. The fields are FormView1_ID, FormView1_Name, ... Following insertion in FormView1 I want to display a second FormView called FormView2 which is also in insertmode. The fields in FormView2 are FormView2_ID, FormView1_ID, FormView2_whatever etc. I want to insert a new record in FormView2 where FormView1_ID is the ID of the just inserted FormView1 record. I have had a fairly intensive trawl through the MSDN walkthroughs, how tos etc but could not find anything I could apply to my situation. If there's something out there please point me at it. Anyway, I decided to try to pass the ID from the first to the second FormView using OnInserting method for FormView2 and by determining the value of FormView1_ID using FindControl. But I'm getting an error! The common one 'Object reference not set to an instance of an object.'. Here's my method in its entirety. protected void FormView2_Sqldatasource2_Inserting(Object sender, SqlDataSourceCommandEventArgs e) { TextBox NewID = null; NewID = (TextBox)FormView1.FindControl("FormView1_ID"); SqlDataSource2.InsertParameters["FormView1_ID"].DefaultValue = NewID.Text; } This error occurs at the line SqlDataSource2.InsertParameters["FormView1_ID"].DefaultValue = NewID.Text; Thanks Maj
-
I want to pass a value from one formview to a second, FormView1 to FormView2. I start with FormView1 and insert a record. The fields are FormView1_ID, FormView1_Name, ... Following insertion in FormView1 I want to display a second FormView called FormView2 which is also in insertmode. The fields in FormView2 are FormView2_ID, FormView1_ID, FormView2_whatever etc. I want to insert a new record in FormView2 where FormView1_ID is the ID of the just inserted FormView1 record. I have had a fairly intensive trawl through the MSDN walkthroughs, how tos etc but could not find anything I could apply to my situation. If there's something out there please point me at it. Anyway, I decided to try to pass the ID from the first to the second FormView using OnInserting method for FormView2 and by determining the value of FormView1_ID using FindControl. But I'm getting an error! The common one 'Object reference not set to an instance of an object.'. Here's my method in its entirety. protected void FormView2_Sqldatasource2_Inserting(Object sender, SqlDataSourceCommandEventArgs e) { TextBox NewID = null; NewID = (TextBox)FormView1.FindControl("FormView1_ID"); SqlDataSource2.InsertParameters["FormView1_ID"].DefaultValue = NewID.Text; } This error occurs at the line SqlDataSource2.InsertParameters["FormView1_ID"].DefaultValue = NewID.Text; Thanks Maj
Got it. I was casting incorrectly. Method should look like: protected void FormView2_Sqldatasource2_Inserting(Object sender, SqlDataSourceCommandEventArgs e) { Label NewID = null; NewID = (Label)FormView1.FindControl("FormView1_ID"); SqlDataSource2.InsertParameters["FormView1_ID"].DefaultValue = NewID.Text; }