ASP. NET getting started

Source: Internet
Author: User

1. First, bind an "nclass table" in the database tutorial"


Show sourceview sourceprint? 1 dataset ds = getdataset ("select * from nclass ");

2 this. combobox1.displaymember = "classname ";

3 this. combobox1.valuemember = "classid ";

4 this. combobox1.datasource = ds. tables [0];

"Displaymember" attribute: in the most popular words, it is to be displayed to the user, bind the "classname" Field of the "nclass" table in the database;

"Valuemember" attribute: gets or sets the value of an attribute. The value is bound to the "classid" Field of "nclass" in the database;

Dataset ds = getdataset ("select * from nclass ");
This. combobox1.displaymember = "classname ";
This. combobox1.valuemember = "classid ";
This. combobox1.datasource = ds. tables [0];


2. Test the value of the corresponding attribute after the combobox is selected:

Show sourceview sourceprint? 1 debug. writeline (this. combobox1.selectedindex); 2 3 debug. writeline (this. combobox1.selectedvalue. tostring (); 4 5 debug. writeline (this. combobox1.text); 6 7 debug. writeline (this. combobox1.selecteditem. gettype (); this. combobox1.selectedindex: if the first drop-down option in combobox is selected, this attribute is used to obtain the index value of the first drop-down option. The index value here is "0" and increases in turn;

This. combobox1.selectedvalue: this attribute obtains the value corresponding to the "classid" field of "nclass" in the database;

Debug. writeline (this. combobox1.selectedindex );

Debug. writeline (this. combobox1.selectedvalue. tostring ());

Debug. writeline (this. combobox1.text );

Debug. writeline (this. combobox1.selecteditem. gettype ());


This. combobox1.text: this attribute obtains the selected text content from the current drop-down menu;

This. combobox1.selecteditem. gettype (): this attribute gets the type of each row selected from the current drop-down menu.

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.