这是我的aspx编码
[WebMethod]
public static CountryDetails[] BindDatatoDropdown()
{
DataTable dt = new DataTable();
List<CountryDetails> details = new List<CountryDetails>();
using (SqlConnection con = new SqlConnection(@"Data Source=DEVSYS;Initial Catalog=Items;Persist Security Info=True;User ID=sa;Password=*****"))
{
using (SqlCommand cmd = new SqlCommand("SELECT ItemTypeID,ItemType FROM ItemTypeTable", con))
{
con.Open();
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.Fill(dt);
foreach (DataRow dtrow in dt.Rows)
{
CountryDetails country = new CountryDetails();
country.CountryId = Convert.ToInt32(dtrow["ItemTypeID"].ToString());
country.CountryName = dtrow["ItemType"].ToString();
details.Add(country);
}
}
}
return details.ToArray();
}
public class CountryDetails
{
public int CountryId { get; set; }
public string CountryName { get; set; }
}
我想使用 Jquery 绑定下拉列表。但我的它只显示错误警报这是我的设计编码
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script type="text/javascript" src="jquery.selectboxes.min.js"></script>
<script type="text/javascript">
$(document).ready(function () {
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "WebForm1.aspx/BindDatatoDropdown",
data: "{}",
dataType: "json",
success: function (data) {
alert("hi");
$.each(data.d, function (key, value) {
$("#ddlCountry").append($("<option></option>").val(value.CountryId).html(value.CountryName));
});
},
error: function ajaxError(response) {
alert(response.status + ' ' + response.statusText);
}
});
});
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:DropDownList ID="ddlCountry" runat="server" />
</div>
</form>
只是我想在页面加载时在下拉列表中绑定项目详细信息。它总是显示错误警报。它说 500 内部服务器错误