Asp. NET two-level linkage detail process without refresh using DropDownList

Source: Internet
Author: User

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

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.