Multi-level selection problem ASP implementation (can enter the essence?) )

Source: Internet
Author: User
When you develop a network application, you often encounter multiple-level selection problems, i.e., the optional information for the "child" tier depends on the data selected at the parent level. For example, a Web page contains two select input controls, one for list alternatives ("parent" level selection) and another for List province information ("Child" level selection). When a user selects a country in the first select input control (the "parent" selection), the option to another select input control (the "Child" level selection) is changed to the state option of the corresponding country, and the relationship between them is dynamically stored in the database.
Ask a question
The traditional solution can be described as: the user selects the "parent" level selection, through the form submission, by the appropriate handler from the database to extract the "child" level of the selected information, and refresh the client page of the "Child" level of the selected data.
The disadvantage of adopting this approach is that:
One or more ASP programs must be written to handle the user's request separately, the program code quality is not high;
When the series is over two, it is necessary to solve the problem of saving the choice information at the "grandfather" level;
Every time the user's modification or browsing multi-level information, must be repeated to obtain multi-level information, so that increased the burden on the server, the response speed is slow.
In view of the problems existing in the above scheme, the author found a solution in practice. This method flexibly applies the input control object hidden in HTML language, when the amount of data in hidden is less than 2K, it can download multilevel information to the client at a time, and through the interaction of server-side script and client script, complete multilevel selection directly on the client.
Solving method
The input control object in HTML language hidden can store string data in a name-value way, and the control object is not visible on the client interface.
Using this input control, multilevel selection information in the database can be encoded according to certain rules and stored in multiple hidden objects. When the user clicks on the parent option, the client program locates the corresponding hidden object according to the corresponding relation, decodes the string information in the hidden object, and refreshes the child Selection object.
Among them, the server-side script needs to complete the work is the multi-level information in the database in order to extract, and the same level of information data according to a certain rule code to form a string, stored in a different hidden object, and the task that client script needs to do is to decode the string data in hidden object, and is displayed in the child Selection object.
It is important to note that the string encoding of the data is a key factor in the success of this method, so the encoding method must be guaranteed to be correct.
Concrete implementation
The following is an example of the two-level selection in the country and province, and introduces the implementation method of multilevel selection in ASP.
Tables containing level two information in SQL Server 7.0 database countrydoc are countryname char (20) and Provincename char (20) respectively.
Considering that the country name, state name is string data, and does not contain the character "0", a 5 consecutive character "0" is used as the separator between different data items when the encoding method is selected. After the code of the province data specific form of "Beijing 00000 Shanghai 00000 Heilongjiang 00000 Jilin."

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.