ComboBox三级关联
<ext:ScriptManager ID="ScriptManager1" runat="server"> <Listeners> <DocumentReady Handler="#{ProvinceStore}.load();" /> </Listeners> </ext:ScriptManager> <ext:Store runat="server" ID="ProvinceStore"> <Proxy> <ext:HttpProxy Method="POST" Url="../WebService/GetProvince.asmx/GetProvicesByRegion" /> </Proxy> <Reader> <ext:XmlReader Record="Province"> <Fields> <ext:RecordField Name="ProvinceID" Type="String" Mapping="ProvinceID" /> <ext:RecordField Name="ProvinceName" Type="String" Mapping="ProvinceName" /> </Fields> </ext:XmlReader> </Reader> <BaseParams> <ext:Parameter Name="regionName" Value="#{cmbRegion}.getValue()" Mode="Raw" /> </BaseParams> <Listeners> <%--<Load Handler="#{cmbProvince}.setValue(#{cmbProvince}.store.getAt(0).get('ProvinceID'));" />--%> </Listeners> </ext:Store> <ext:Store runat="server" ID="CityStore"> <Proxy> <ext:HttpProxy Method="POST" Url="../WebService/GetCity.asmx/GetCityByProvinceId" /> </Proxy> <Reader> <ext:XmlReader Record="City"> <Fields> <ext:RecordField Name="CityId" Type="String" Mapping="CityId" /> <ext:RecordField Name="CityName" Type="String" Mapping="CityName" /> </Fields> </ext:XmlReader> </Reader> <BaseParams> <ext:Parameter Name="provinceId" Value="#{cmbProvince}.getValue()" Mode="Raw" /> </BaseParams> <Listeners> <%--<Load Handler="#{CityStore}.setValue(#{CityStore}.store.getAt(0).get('CityId'));" />--%> </Listeners> </ext:Store> <ext:Store runat="server" ID="DistrictStore"> <Proxy> <ext:HttpProxy Method="POST" Url="../WebService/GetDistrict.asmx/GetDistrictByCityId" /> </Proxy> <Reader> <ext:XmlReader Record="District"> <Fields> <ext:RecordField Name="DistrictID" Type="String" Mapping="DistrictID" /> <ext:RecordField Name="DistrictName" Type="String" Mapping="DistrictName" /> </Fields> </ext:XmlReader> </Reader> <BaseParams> <ext:Parameter Name="CityID" Value="#{cmbCity}.getValue()" Mode="Raw" /> </BaseParams> <Listeners> <%--<Load Handler="#{CityStore}.setValue(#{CityStore}.store.getAt(0).get('CityId'));" />--%> </Listeners> </ext:Store>
<ext:ComboBox ID="cmbCity" runat="server" FieldLabel="城市" EmptyText="Loading..." Editable="false" TypeAhead="true" Mode="Local" StoreID="CityStore" ForceSelection="true" TriggerAction="All" DisplayField="CityName" ValueField="CityId" ValueNotFoundText="Loading..."> <Listeners> <Select Handler="#{cmbDistrict}.clearValue();#{DistrictStore}.load();" /> </Listeners> </ext:ComboBox> <ext:ComboBox ID="cmbDistrict" runat="server" FieldLabel="区/县" StoreID="DistrictStore" EmptyText="Loading..." Editable="false" TypeAhead="true" Mode="Local" SelectOnFocus="true" ForceSelection="true" TriggerAction="All" DisplayField="DistrictName" ValueField="DistrictID" ValueNotFoundText="Loading..."> <Listeners > <Select Handler="#{txtAddress}.setValue(#{cmbProvince}.getText()+#{cmbCity}.getText()+#{cmbDistrict}.getText());" /> </Listeners> </ext:ComboBox> <ext:ComboBox ID="cmbRegion" runat="server" FieldLabel="区域" Editable="false" TypeAhead="true" Mode="Local" ForceSelection="true" TriggerAction="All" SelectOnFocus="true" EmptyText="Select a Region"> <SelectedItem Value="华南地区" /> <Listeners> <Select Handler="#{cmbProvince}.clearValue();#{cmbCity}.clearValue();#{cmbDistrict}.clearValue();#{ProvinceStore}.load();" /> </Listeners> <Items> <ext:ListItem Text="华东地区" Value="华东地区" /> <ext:ListItem Text="华北地区" Value="华北地区" /> <ext:ListItem Text="东北地区" Value="东北地区" /> <ext:ListItem Text="华中地区" Value="华中地区" /> <ext:ListItem Text="华南地区" Value="华南地区" /> <ext:ListItem Text="西南地区" Value="西南地区" /> <ext:ListItem Text="西北地区" Value="西北地区" /> <ext:ListItem Text="港澳台" Value="港澳台" /> </Items> </ext:ComboBox> <ext:ComboBox ID="cmbProvince" runat="server" StoreID="ProvinceStore" EmptyText="Loading..." Editable="false" TypeAhead="true" Mode="Local" SelectOnFocus="true" ForceSelection="true" TriggerAction="All" DisplayField="ProvinceName" ValueField="ProvinceID" ValueNotFoundText="Loading..." FieldLabel="省份"> <Listeners> <Select Handler="#{cmbCity}.clearValue();#{cmbDistrict}.clearValue();#{CityStore}.load();" /> </Listeners> </ext:ComboBox>
public class GetProvince : System.Web.Services.WebService { [WebMethod] public List<Province> GetProvicesByRegion(string regionName) { switch (regionName) { case null: return null; default: { var ds = Utilities.GetDsByTableName("select ProvinceID,ProvinceName from S_Province where Region='" + regionName + "' order by ProvinceID"); return (from DataRow dr in ds.Tables[0].Rows select new Province(dr["ProvinceID"].ToString(), dr["ProvinceName"].ToString())).ToList(); } } } public class Province { public Province() { } public Province(string provinceId, string provinceName) { ProvinceID = provinceId; ProvinceName = provinceName; } public string ProvinceID { get; set; } public string ProvinceName { get; set; } } }