The Combobox drop-down box is linked at two levels, and the combobox drop-down box is linked at two levels.

Source: Internet
Author: User

The Combobox drop-down box is linked at two levels, and the combobox drop-down box is linked at two levels.

Two levels of interaction in the drop-down box is a situation that we often encounter during development. For example, in a student management system, the score of a student's examination is queried Based on the grade, subject, and name. The grades and subjects are limited data (databases) in the hard disk, and the students can be manually specified by users, at this time, there are two tables in the database: grade and subject. Each subject corresponds to a grade. Therefore, we can use two drop-down boxes (Combobox) to store grade and subject information for users to choose from. The interface is as follows:

Model expansion 1 int gradeid = Convert. toInt32 (cboGrade. selectedValue); // obtain the selected grade number 2 3 List = subjectBll. getAllSubject (gradeid); // you can call this operation to query the corresponding account information under the specified year ID. valueMember = "subjectid"; 6 cboSubject. displayMember = "subjectname"; 7 cboSubject. dataSource = list; 1 int gradeid = Convert. toInt32 (cboGrade. selectedValue); // obtain the selected grade number 2 3 List <Subject> list = subjectBll. getAllSubject (gradeid); // you can call this operation to query the corresponding account information under the specified year ID. valueMember = "subjectid"; 6 cboSubject. displayMember = "subjectname"; 7 cboSubject. dataSource = list;

SelectedValue attribute in the drop-down box

Property prototype:

Common Errors:

Error Analysis: after the experiment, we can confirm that the code for binding the data source is placed behind the attribute settings to solve this error, I personally think that if you bind the data source first, the system will automatically set the valuemember attribute value to the type of the bound set and then set Valuemember, and the system will not change it!

Related Article

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.