Get ID after combox binding -- manually delete and add selectedindexchanged event

Source: Internet
Author: User

The third-party control solves this problem: After a combox is bound with a name and ID, it may cause an issue to get the ID. You need to set the manual deletion and add the selectedindexchanged event.

 

Code:

Private void Tc () // combox binding name
{
Sqlconnection con = new sqlconnection (****);
Sqldataadapter ad = new sqldataadapter ("select typeid, typename from typeB select stateid, statename from Stateb", con );
// Sqlcommand sqlcom = new sqlcommand ("select typeid, typename from typeB select stateid, statename from Stateb", con );


Dataset DS = new dataset ();
// Datatable dt = new datatable ();
Ad. Fill (DS );
// Ad. Fill (DT );
// SHz = new int [Ds. Tables [0]. Rows. Count];
// For (I = 0; I <Ds. Tables [0]. Rows. Count; I ++)
//{
// Comboboxex2.items. Add (Ds. Tables [0]. Rows [I] [1]);

// SHz [I] = convert. toint32 (Ds. tables [0]. rows [I] [0]); // It is called when an ID is used later. It cannot be displayed here.

//}
// Shz1 = new int [Ds. Tables [1]. Rows. Count];
// For (I = 0; I <Ds. Tables [1]. Rows. Count; I ++)
//{
// Comboboxex1.items. Add (Ds. Tables [1]. Rows [I] [1]);
// Shz1 [I] = convert. toint32 (Ds. Tables [1]. Rows [I] [0]);
//}

Comboboxex1.datasource = Ds. Tables [0];
Comboboxex1.displaymember = "typename ";
Comboboxex1.valuemember = "typeid ";

Combobox1.selectedindexchanged-= new eventhandler (combobox?selectedindexchanged); // manually delete the selectedindexchanged event
Combobox1.datasource = Ds. Tables [0];
Combobox1.displaymember = "typename ";
Combobox1.valuemember = "typeid ";
Combobox1.selectedindexchanged + = new eventhandler (combobox?selectedindexchanged); // manually add the selectedindexchanged event

// Manually delete and add, and then obtain its ID. Otherwise, an error is returned... Third-party controls solve this problem and can be compared and learned.
}

 

Private void comboboxex1_selectedindexchanged (Object sender, eventargs E)
{
// Typid = sHz [comboboxex1.selectedindex]; // The obtained ID. When the SQL statement has where id = '+ typid + "'
Typid = convert. toint32 (comboboxex1.selectedvalue );
}

 

Private void combobox#selectedindexchanged (Object sender, eventargs E)
{
Typid1 = convert. toint32 (combobox1.selectedvalue );
}

 

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.