0
這是我的aspx編碼綁定下拉使用JQuery
[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內部服務器錯誤
我已經找到了問題。 Jquery腳本只綁定有限的數據。它只綁定近1000個數據。我想綁定2000,以便它顯示錯誤 – Golda