This is a DropDownList implementation of the provincial and municipal level three linkage, record the
<asp:scriptmanager id= "ScriptManager1" runat= "Server" >/asp:ScriptManager>
<asp:updatepanel id= "UpdatePanel1" runat= "Server" > <contenttemplate><p><span class= "Redcolor" >* </span> Select a region: <asp:dropdownlist id= "Provinceselect" autopostback= "True" &nbs p;runat= "Server" onselectedindexchanged= "Getcityname_onclick" ></asp:dropdownlist><asp:d ropdownlist runat= "Server" id= "Cityselect" autopostback= "True" onselectedindexchanged= " Getcounty_onclick " ></asp:dropdownlist><asp:dropdownlist autopostback= "True" runat= "Server" id= "County" ></asp:DropDownList></p> </ contenttemplate> <Triggers> <asp:asyncpostbacktrigger controlid= "Provinceselect" EventName= " SelectedIndexChanged " /> </Triggers>
</asp:UpdatePanel>
Background code:
protected void Page_Load (object sender, EventArgs e) { if (! IsPostBack) { Provinceselect.datasource = BFL. Getprivoces (); Provinceselect.datatextfield = "Regionname"; Provinceselect.datavaluefield = "RegionID"; Provinceselect.databind (); ProvinceSelect.Items.Insert (0, New ListItem ("Please select", String.) Empty)); CitySelect.Items.Insert (0, New ListItem ("Please select", String.) Empty)); County.Items.Insert (0, New ListItem ("Please select", String.) Empty)); } }
#region Provinces and Cities data binding//city-bound public void Getcityname_onclick (object sender, EventArgs e) {citys Elect. DataSource = BFL. Getcitys (int. Parse (ProvinceSelect.SelectedItem.Value)); Cityselect.datatextfield = "Regionname"; Cityselect.datavaluefield = "RegionID"; Cityselect.databind (); County.Items.Insert (0, New ListItem ("Please select", String.) Empty)); }
County-bound public void Getcounty_onclick (object sender, EventArgs e) {county.datasource = BFL. Getcitys (int. Parse (CitySelect.SelectedItem.Value)); County.datatextfield = "Regionname"; County.datavaluefield = "RegionID"; County.databind (); County.Items.Insert (0,new ListItem ("Please select", String.) Empty)); } #endregion
Three-level linkage of provincial and municipal level implemented with DropDownList