我使用 asp.net 网络表单文本框进行自动完成。当我输入任何 value 时,在我的文本框中,没有显示任何建议。这是我在 Default.aspx 中的代码:
<link rel="Stylesheet" href="https://ajax.aspnetcdn.com/ajax/jquery.ui/1.8.10/themes/redmond/jquery-ui.css" />
<script src="https://ajax.aspnetcdn.com/ajax/jquery/jquery-1.8.0.js"></script>
<script src="https://ajax.aspnetcdn.com/ajax/jquery.ui/1.8.22/jquery-ui.js"></script>
<script type="text/javascript" language="javascript">
$(document).ready(function () {
$('#txtName').autocomplete({
source: 'AutoCompleteCase.ashx'
});
});
</script>
<asp:TextBox ID="txtName" runat="server"></asp:TextBox>
AutoCompleteCase.ashx:
public void ProcessRequest(HttpContext context)
{
string term = context.Request["term"] ?? "";
List<string> list = new List<string>();
SqlConnection con = new SqlConnection(@"Data Source=PC01\SQL2012;Initial Catalog=elawdb;Integrated Security=True");
string sqlquery = string.Format("Select ReferredTitle from refcases where ReferredTitle LIKE '%{0}%'", term);
con.Open();
SqlCommand cmd = new SqlCommand(sqlquery, con);
SqlDataReader rdr = cmd.ExecuteReader();
while (rdr.Read())
{
list.Add(rdr["ReferredTitle"].ToString());
}
JavaScriptSerializer js = new JavaScriptSerializer();
context.Response.Write(js.Serialize(list));
}
知道哪里出错了吗?
回答1
请浏览这个 https://www.aspdotnet-suresh.com/2012/03/jquery-ui-autocomplete-textbox-with.html?m=1,类似于用于获取自动完整文本的概念。