自动完成的jQuery在WebForm中不起作用
我使用ASP.NET WebForm文本框进行自动完成。在我的文本框中输入任何值时,没有显示建议。这是我在默认值中的代码: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));
}
出现在哪里?
I use asp.net webform textbox for autocomplete. In my textbox when i type any value, there is no suggestion shown. Here is my code in 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));
}
Any idea where it go wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
请浏览此,
类似的概念用于获取自动完成文本。
please walk through this link,
similar kind of concept used to get the auto complete text.