日期:2014-05-17 浏览次数:20500 次
if (!IsPostBack) { RegionalInformation ri = new RegionalInformation(); string[][] allProvinces = ri.GetProvinces(); for (int i = 0; i < allProvinces.Length; i++) { ListItem lip = new ListItem(allProvinces[i][1], allProvinces[i][0]); DDLProvince.Items.Add(lip); } string[][] citiesOfProvince = ri.GetCitiesOfProvince("1"); for (int j = 0; j < citiesOfProvince.Length; j++) { ListItem li = new ListItem(citiesOfProvince[j][1], citiesOfProvince[j][0]); DDLCity.Items.Add(li); } }
protected void DDLProvince_SelectedIndexChanged(object sender, EventArgs e) { RegionalInformation ri = new RegionalInformation(); string a = Convert.ToString(DDLProvince.SelectedIndex + 1); string[][] citiesOfProvince = ri.GetCitiesOfProvince(a); DDLCity.Items.Clear(); for (int j = 0; j < citiesOfProvince.Length; j++) { ListItem li = new ListItem(citiesOfProvince[j][1], citiesOfProvince[j][0]); DDLCity.Items.Add(li); } }
<asp:DropDownList ID="DDLProvince" runat="server" CssClass="select" AutoPostBack="True" Height="22px" onselectedindexchanged="DDLProvince_SelectedIndexChanged" Width="150px"> </asp:DropDownList> <asp:DropDownList ID="DDLCity" runat="server" CssClass="select" CausesValidation="True" Height="22px" Width="150px"> </asp:DropDownList>