【发布时间】:2017-01-28 05:06:50
【问题描述】:
在您的.aspx 页面中添加名称为ProductType 的控件,该控件属于文本框类型
[WebMethod(EnableSession = true)]
public static List<string> GetAutoCompleteDataProduct(string ProductType)
{
// string pid = "";
ProductMasterBL objProductMasterBl = new ProductMasterBL();
DataTable dtSearchProducts = objProductMasterBl.GetProductTypes(ProductType);
List<string> result = new List<string>();
for (int i = 0; i < dtSearchProducts.Rows.Count; i++)
{
result.Add(dtSearchProducts.Rows[i]["ProductName"].ToString());
}
if (result.Count == 0)
{
result.Add("No match found.");
}
return result;
}
代码后面的代码:
$(document).ready(function () {
SearchText();
});
function SearchText() {
// var txtSearch = document.getElementById('txtProductType');
$("#txtProductType").autocomplete({
source: function (request, response) {
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "Customers.aspx/GetAutoCompleteDataProduct",
data: "{'ProductType':'" + request.term +"'}",
dataType: "json",
success: function (data) {
response(data.d);
},
error: function (result) {
alert("Error");
},
focus: function () {
// prevent value inserted on focus
return false;
},
});
}
});
}
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js" type="text/javascript"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js" type="text/javascript"></script>
<link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css" rel="Stylesheet" type="text/css" />
以上代码均属于代码隐藏代码、JavaScript代码和脚本函数使用的链接
【问题讨论】:
-
也提供html代码
-
-
@dhanamounika:你有什么错误吗?
-
如果您遇到任何错误,请告诉我。我会帮助您解决它
标签: javascript c# asp.net ajax