本文介绍了数据绑定到下拉列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
这是我的网络服务方法。
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>
推荐答案
这篇关于数据绑定到下拉列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!