自动完成的jQuery在WebForm中不起作用

发布于 2025-01-30 05:11:14 字数 1512 浏览 1 评论 0原文

我使用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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

冰葑 2025-02-06 05:11:14

please walk through this link,
similar kind of concept used to get the auto complete text.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文