Asp. NET Getting Started Tutorial

Source: Internet
Author: User

1, first, bind a "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 their most popular words, is to show to the user, the Binding database table "NClass" of the "ClassName" field;

ValueMember property: Gets or sets the value of a property that is bound to the "classid" field of the table "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, after the test ComboBox selected, what is the value of the corresponding property:

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 at this time, this property is the index value for the current first drop-down option, and I have the index value "0", incremented sequentially;

This.combobox1.selectedvalue: This property obtains the corresponding value of the "ClassID" field in the table "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 property gets the text content selected in the current Drop-down menu;

This.combobox1.selecteditem.gettype (): This property gets the type of each row object that the current Drop-down menu selects

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.