数据绑定到下拉列表

问题描述:

大家好,



这是我的网络服务方法。

Hi everyone,

This is my webservice method.

[WebMethod]
    public List<cls_Countries> GetCountries()
    {
        cls_GetLocations locations = new cls_GetLocations();
        return locations.GetCountries();
    }





这是我在课堂上的方法



This is my method in class

public cls_GetLocations()
        {
        }
        public List<cls_Countries> GetCountries()
        {
            List<cls_Countries> list=new List<cls_Countries>();
            try
            {
                DataTable dt= SqlHelper.ExecuteDataset(SqlHelper.ConnString, CommandType.StoredProcedure, "Proc_GetCountries").Tables[0];
                foreach (DataRow dr in dt.Rows)
                {
                    cls_Countries country = new cls_Countries();
                    country.CountryID = dr["CountryId"].ToString();
                    country.CountryName = dr["Country"].ToString();
                    list.Add(country);
                }
            }
            catch (Exception ex)
            {
                throw (ex);
            }

            return list;
        }





我想绑定下拉我尝试下面的代码但它不会工作所以请解决并提供给我解决方案





I want to bind to drop down I tried below code but it wont work so please solve and provide me correct solution

<script type="text/javascript" >

    $(function () {
        $.ajax({
            type: "POST",
            contentType: "application/json; charset=utf-8",
            url: 'WebServices/AutoComplete.asmx/GetCountries',
            data: "{}",
            datatype: "json",
            success:
                function (data, event) {
                    $.map(data.d, function (item) {
                        alert(item);
                        //$("#<%= drpCountry.ClientID %>").index = item.countryid;
                        //$("#<%= drpCountry.ClientID %>").val = item.countryname;
                        //alert(item.countryname);
                    });
                }

        });

    });                                                         
</script>

function ( ){


.ajax({
type: POST
contentType: application / json; charset = utf-8
url:' WebServices / AutoComplete.asmx / GetCountries'
data : {}
datatype: json
成功:
function (数据, event){
.ajax({ type: "POST", contentType: "application/json; charset=utf-8", url: 'WebServices/AutoComplete.asmx/GetCountries', data: "{}", datatype: "json", success: function (data, event) {


.map(data.d, function (item){
alert(item);
//
.map(data.d, function (item) { alert(item); //