简体   繁体   English

在客户端加载 aspx 组合框

[英]Loading the aspx combobox at client side

I have used aspx combobox and bind the values at the client side through ajax call, the values are loaded but was not displayed in the combobox, i want to know where i did the mistake我已经使用 aspx 组合框并通过 ajax 调用在客户端绑定值,值已加载但未显示在组合框中,我想知道我在哪里做错了

please find the code below:请找到下面的代码:

 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;
            });

use [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;
    }

You can use AddItem() Method您可以使用 AddItem() 方法

here are the References about dynamic load item in the Combobox at clientside(js)这是有关客户端组合框中动态加载项目的参考资料(js)

https://docs.devexpress.com/AspNet/js-ASPxClientComboBox.AddItem(text) https://docs.devexpress.com/AspNet/js-ASPxClientComboBox.AddItem(文本)

and this is the example or demo这是示例或演示

https://codecentral.devexpress.com/e1332/ https://codecentral.devexpress.com/e1332/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM