標記正確的方式來ASP.net CascadingDropDown的編程方式觸發更改事件使用JavaScript
<asp:ScriptManager runat="server" />
Country Code
<asp:TextBox ID="CoutryCodeTextBox" runat="server" onblur="selectCountry(this.id);">
</asp:TextBox>
<asp:DropDownList ID="CountryDropDownList" runat="server">
</asp:DropDownList>
<ajaxToolkit:CascadingDropDown
ID="CountryDropDownListCascadingDropDown" runat="server"
TargetControlID="CountryDropDownList"
Category="Country"
ServiceMethod="GetCountries"
ServicePath="~/CountryData.asmx"
LoadingText="Loading ..."
PromptText="SELECT">
</ajaxToolkit:CascadingDropDown>
<asp:DropDownList ID="CityDropDownList" runat="server">
</asp:DropDownList>
<ajaxToolkit:CascadingDropDown
ID="CityDropDownListCascadingDropDown" runat="server"
ParentControlID="CountryDropDownList"
TargetControlID="CityDropDownList"
Category="City" ServiceMethod="GetCities"
ServicePath="~/CountryData.asmx"
LoadingText="Loading ..."
PromptText="SELECT">
</ajaxToolkit:CascadingDropDown>
Web服務(〜/ CountryData.asmx)
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
[ScriptService]
public class CountryData : System.Web.Services.WebService
{
[WebMethod]
public CascadingDropDownNameValue[] GetCountries(string knownCategoryValues, string category)
{
List<CascadingDropDownNameValue> values = new List<CascadingDropDownNameValue>();
values.Add(new CascadingDropDownNameValue("United States", "US"));
values.Add(new CascadingDropDownNameValue("Canada", "CA"));
return values.ToArray();
}
[WebMethod]
public CascadingDropDownNameValue[] GetCities(string knownCategoryValues, string category)
{
StringDictionary kv = CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues);
string country = kv["Country"];
List<CascadingDropDownNameValue> values = new List<CascadingDropDownNameValue>();
switch (country)
{
case "US":
values.Add(new CascadingDropDownNameValue("California", "CA"));
values.Add(new CascadingDropDownNameValue("New York", "NY"));
break;
case "CA":
values.Add(new CascadingDropDownNameValue("Toronto", "TO"));
values.Add(new CascadingDropDownNameValue("Montreal", "MO"));
break;
}
return values.ToArray();
}
}
jQuery的
var selectCountry = function (id)
{
var countryCodeTextBox = $("#" + id);
var countryDropDownList = $("#CountryDropDownList");
countryDropDownList.val(countryCodeTextBox.val());
countryDropDownList.change();
}
的javascript函數更改CountryDropDownList的選定值。但是,級聯控件CityDropDownList不會自動填充。
什麼是觸發使用jQuery,使相關的控制(S)能自動級聯父控件更改事件的正確方法?
請問,當你在這裏使用的方法是觸發:http://stackoverflow.com/questions/499405/change-the-selected-value-of-a-drop-down-list-with-jquery –
這正是我在做。它沒有幫助。 –