In April 5, I encountered a headache with the gridview.

Source: Internet
Author: User
Tags object serialization

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.