Is FormView the best approach for me?
-
I have a dilemma. I'm writing an application which requires a very simple set of forms to allow new records to be added to a table. In simple English Form1 - Contains Link to 'New Record' button which transfers to Form2 Form 2 Provides textboxes etc to allow a new record to be input. Provides Insert and Cancel buttons On Insert, displays just inserted record in readonly mode. Also displays Edit and Cancel buttons. On Cancel returns to Form1 It's clearly a very simple exercise but in trying to implement this using FormView I just keep hitting one problem after the other. For example, by default following an insert, FormView does not return you to the just inserted record but to the first row in the db. I've got that solved but now am hitting other problems. Here's one. I've set the defaultmode for the formview to insert so that the first time I get a blank insert template displayed. After insert I want to go to readonly mode and show the just inserted record but cannot achieve this. Here's my code: protected void SqlDataSource2_Inserted(Object sender, SqlDataSourceStatusEventArgs e) { FormView1.ChangeMode(FormViewMode.ReadOnly); } A new blank template is displayed. The mode is not changed to Readonly. I've also tried using the FormView ItemInserted event but the same happens. Does anyone have a solution or am I using the wrong tool. I want to use FormView if possible/appropriate because Sqldatasource handles data so easily. Thanks Maj
-
I have a dilemma. I'm writing an application which requires a very simple set of forms to allow new records to be added to a table. In simple English Form1 - Contains Link to 'New Record' button which transfers to Form2 Form 2 Provides textboxes etc to allow a new record to be input. Provides Insert and Cancel buttons On Insert, displays just inserted record in readonly mode. Also displays Edit and Cancel buttons. On Cancel returns to Form1 It's clearly a very simple exercise but in trying to implement this using FormView I just keep hitting one problem after the other. For example, by default following an insert, FormView does not return you to the just inserted record but to the first row in the db. I've got that solved but now am hitting other problems. Here's one. I've set the defaultmode for the formview to insert so that the first time I get a blank insert template displayed. After insert I want to go to readonly mode and show the just inserted record but cannot achieve this. Here's my code: protected void SqlDataSource2_Inserted(Object sender, SqlDataSourceStatusEventArgs e) { FormView1.ChangeMode(FormViewMode.ReadOnly); } A new blank template is displayed. The mode is not changed to Readonly. I've also tried using the FormView ItemInserted event but the same happens. Does anyone have a solution or am I using the wrong tool. I want to use FormView if possible/appropriate because Sqldatasource handles data so easily. Thanks Maj
Hi there, Basically, the FormView returns to its default mode after the inserting command is complete, so in the event handler of the ItemInserted event of the FormView control, you can simple do as the following:
FormView1.DefaultMode = FormViewMode.ReadOnly;
-
Hi there, Basically, the FormView returns to its default mode after the inserting command is complete, so in the event handler of the ItemInserted event of the FormView control, you can simple do as the following:
FormView1.DefaultMode = FormViewMode.ReadOnly;
Thanks. That works. I had already tried FormView1.ChangeMode(FormViewMode.ReadOnly); in the event handler of the ItemInserted event of the FormView control and while degugging indicated that the mode was set to ReadOnly, the form presented following insert was a blank insert template. Something to do with Postback perhaps? Although I have a good working solution now I'd like to understand why the ChangeMode method didn't work. Any ideas? Thanks Maj