我有一个TextBox
,如果我键入任何文本值,则使用 AJAX 从数据库中获取并显示结果,但我必须根据此 AJAX 数据绑定不同的值和文本,TextBox
即我必须显示来自列的文本AcctName
和来自的值列AcctName
,但我无法做到这一点。
这是我的服务器端代码:
[WebMethod]
public static List<string> GetAutoCompleteData(string partyname)
{
List<string> result = new List<string>();
DataTable dt;
AccountInfo oAccount = new AccountInfo();
dt = oAccount.GetAccountInfo((int)HttpContext.Current.Session["CompCode"], 0);
if (dt.Rows.Count > 0)
{
for (int i = 0;i < dt.Rows.Count; i++)
{
result.Add(dt.Rows[i]["AcctCode"].ToString() + ";"+ result.Add(dt.Rows[i]["AcctName"].ToString() + ";"););
}
}
return result;
}
HTML:
<div class="ui-widget">
<input id="txtSearch" runat="server" class="autosuggest" style="min-width:100px;height:20px;" type="text" />
</div>
JavaScript:
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.1/jquery-ui.min.js"></script>
<script>
$(document).ready(function() {
SearchText();
});
function SearchText() {
$(".autosuggest").autocomplete({
source: function(request, response) {
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "PurchaseOrder.aspx/GetAutoCompleteData",
data: "{'partyname':'" + document.getElementById('ctl00_ContentPlaceHolder1_txtSearch').value + "'}",
dataType: "json",
success: function(data) {
response(data.d);
},
error: function(result) {
alert("Error");
}
});
}
});
}
</script>