Implementation Model:
A webform has two gridview named gridview1 and gridview2 respectively. The following similar data is displayed:
(Table Name T1)
Id C1 C2 type
1 1 1 1
2 2 2 1
3 1 1 1
4 2 2 1
5 1 1 1
6 2 2 1
7 1 1 2
8 2 2 2
9 1 1 2
10 2 2 2
11 1 1 2
12 2 2 2
The data source of gridview1 is select * from T1 where type = 1
The data source of gridview2 is select * from T1 where type = 2
Both the gridview have this column selected, and there are two buttons in this webform, btnup and btndown. The former implements the function of adding the row data selected in gridview1 to gridview2. However, at this time, the selected type value in gridview1 cannot be changed. You must click the OK button on the webpage to officially update the database, this model requires that, if you click the exit button, the operation is automatically canceled by cancel.
Difficulties:
The database must be updated after you click OK.
Object serialization
The lifecycle of webform is different from that of winform. This operation is well solved in winform, because the lifecycle of the form disappears directly in the memory before it ends, however, webform performs operations on the database only when the lifecycle of a request is completed after the request is completed. The previous method was to create an operation list arraylist, which records the information to be moved, and save the arraylist object to viewstate. However, this error is prompted during running.
ProgramThe type "system. Web. UI. webcontrols. datacontrolfieldcell" in "system. Web, version = 2.0.0.0, culture = neutral, publickeytoken = b03f5f7f11d50a3a" is not marked as serializable.
Maybe not.
Whether there are more molding solutions for such problems in Asp.net, I always feel that my methods are stupid and difficult to use.
I thought my BS had a wealth of experience. I didn't expect to be hit by this problem.
Supplement:
There is a basic idea: add the row in the source bound above to the following when you click, and then update the database after you click OK.
The problem is how to save the data above and below after so many PostBack operations.