【发布时间】:2021-01-02 21:58:16
【问题描述】:
我想绑定多个下拉列表,并且所有下拉列表相互依赖。
使用 Web 方法(服务 URL)。
服务返回类型是ExtensionDataObject,我想将此返回类型存储到列表中是否可能我不确定
但是我怎样才能将这个对象绑定到列表中。
ASPX
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function () {
var params = { UserId: 'approver01', WorkflowTypeCode: 4 };
$.ajax({
type: "post",
contentType: "application/json; charset=utf-8",
data: JSON.stringify({ "objectData": params }),
url: 'IP/Service.svc/getdata/GetCountriesName',
dataType: "json",
success: BindCountry,
error: function (xhr, ajaxOptions, thrownError) {
alert(xhr.status);
alert(xhr.responseText);
alert(thrownError);
}
});
function BindCountry(response) {
$.each(response.d, function (key, value) {
appendString = "<option value='" + key + "'>" + value + "</option>";
$("#ddlCountry").append(appendString);
});
}
function ajaxError(response) {
alert(response.status + ' ' + response.statusText);
}
});
</script>
<select id="ddlCountry" runat="server">
<option value="0">--Select Country--</option>
</select>
<select id="ddlCompany" runat="server">
<option value="0">--Select Company--</option>
</select>
<select id="ddlDivision" runat="server">
<option value="0">--Select Devision--</option>
</select>
<select id="ddlLocation">
<option value="0">--Select Location</option>
</select>
.CS 代码 这里我的方法是:为服务引用创建对象,然后添加到列表和返回列表并通过 aspx 调用使用 j 查询 URL 但无法执行相同操作。
[WebMethod]
public static List<CountryList> GetCountriesName(string UserID)
{ //Creating object for service reference.
AlmaraiMasterDataService.MasterDataServiceClient oClient = new AlmaraiMasterDataService.MasterDataServiceClient();
List<CountryList> lst = new List<CountryList>();
lst.Add(oClient.GetActiveCountries); //Error not able to add In List
return lst;
}
public class CountryList
{
public int CountryId { get; set; }
public string CountryName { get; set; }
}
【问题讨论】:
-
请在后端提供
Mymethod的详细信息? -
@SelimYildiz 我再次更新我的问题
标签: jquery asp.net html-select cascadingdropdown