Demo.sql
1 Create TableCar (2 [ID] int Identity,3 [Brand] varchar( -) not NULL,4 [type] varchar( -) not NULL5 )6 Go7 8 Insert intoCar ([Brand],[type])Values('BMW','B'),('BMW','M'),('BMW','W'),9('BENZ','B'),('BENZ','E'),('BENZ','N'),('BENZ','Z'),Ten('HONDA','H'),('HONDA','O'),('HONDA','N'),('HONDA','D'),('HONDA','A'), One('TOYOTA','T'),('TOYOTA','O'),('TOYOTA','Y'),('TOYOTA','A')
Demo.aspx
1<asp:scriptmanager runat="Server">2</asp:ScriptManager>3<asp:updatepanel runat="Server">4<ContentTemplate>5<asp:dropdownlist id="Dropbrand"runat="Server"Onselectedindexchanged="dropbrand_selectedindexchanged"6Width=" $"autopostback="True">7</asp:DropDownList>8<asp:dropdownlist id="DropType"runat="Server"Width=" $">9</asp:DropDownList>Ten</ContentTemplate> One</asp:UpdatePanel>
Demo.aspx.cs
1 protected voidPage_Load (Objectsender, EventArgs e)2 {3 if(!IsPostBack)4 {5 Binddrop ();6 }7 }8 9 Private voidBinddrop ()Ten { One //to bundle data into a drop-down list A stringSqlstr ="SELECT DISTINCT [BRAND] from Car"; -DataTable dt =sqlhelper.executedatatable (SQLSTR); -Dropbrand.datatextfield ="Brand";//set the word that the list displays theDropbrand.datavaluefield ="Brand";//sets the field that is obtained after the list is submitted and understands that the bound data is hidden -Dropbrand.datasource =DT; - Dropbrand.databind (); -DropBrand.Items.Insert (0,NewListItem ("Please select a car brand",""));//add content to the first item, focusing on adding after binding +DropType.Items.Insert (0,NewListItem ("Please select car brand model",""));//add content to the first item, focusing on adding after binding - } + A protected voidDropbrand_selectedindexchanged (Objectsender, EventArgs e) at { - stringSqlstr ="SELECT * from Car where [brand]= '"+ Dropbrand.selectedvalue +"'";//Dropbrand.datavaluefield hides the bound data after the page is loaded, and then queries the DropType to reveal the data behind it . -DataTable dt =sqlhelper.executedatatable (SQLSTR); -Droptype.datatextfield ="type";//Set Dropbrand Event SelectedIndexChanged change the data displayed droptype the list -Droptype.datavaluefield ="ID"; -Droptype.datasource =DT; in Droptype.databind (); -}
Reference Original: http://www.cnblogs.com/cqchai/archive/2011/05/28/2061378.html
Asp. NET two-level linkage detail process without refresh using DropDownList