我使用过aspx组合框并通过ajax调用在客户端绑定值,这些值已加载但未显示在组合框中,我想知道我在哪里做错了
请在下面找到代码:
public static List<string> GetDepartments()
{
ABTestNewEntities obj = new ABTestNewEntities();
List<string> lst = new List<string>();
lst.Add(string.Format("{0}-|-{1}", 0, "Please Select"));
lst.Add(string.Format("{0}-|-{1}", 1, "Develop"));
lst.Add(string.Format("{0}-|-{1}", 2, "Test"));
lst.Add(string.Format("{0}-|-{1}", 3, "HR"));
return lst;
}
$(document).ready(function () {
alert("inside function");
$("#btn").click(function () {
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "NewOrder.aspx/GetDepartments",
data: "",
datetype: "json",
async: false,
success: function (data) {
var response = data.d;
$("#ddldepartment").empty();
for (var i = 0; i < response.length; i++) {
var item = response[i].split("-|-");
var Option = "<option value='" + item[0] + "'>" + item[1] + "</option>";
Option.text = item[1];
Option.value = item[0];
$("#ddldepartment").append(Option);
}
return false;
//});
},
error: function (data) {
alert("Error");
alert(data.error);
return false;
}
});
return false;
});
return false;
});
答案 0 :(得分:0)
使用[WebMethod]
[WebMethod]
public static List<string> GetDepartments()
{
List<string> lst = new List<string>();
lst.Add(string.Format("{0}-|-{1}", 0, "Please Select"));
lst.Add(string.Format("{0}-|-{1}", 1, "Develop"));
lst.Add(string.Format("{0}-|-{1}", 2, "Test"));
lst.Add(string.Format("{0}-|-{1}", 3, "HR"));
return lst;
}
答案 1 :(得分:0)
您可以使用AddItem()方法
这是clientside(js)组合框中的有关动态加载项的参考
https://docs.devexpress.com/AspNet/js-ASPxClientComboBox.AddItem(text)
这是示例或演示