1

asp.net のデータベースから jquery オートコンプリートを使用したいと考えています。minLength オプションを除いて動作しました。次のコードに示すように、いくつかの方法を試しましたが、minLength オプションが機能しませんでした。これを明らかにしてください。ありがとうございました。

これが私のコードです:

<script src="../../../jquery/jquery-1.7.2.js" type="text/javascript"></script>
<script type="text/javascript" src="../../../jquery/jquery.autocomplete.js"></script>
  <script type="text/javascript">
      $(document).ready(function() {
      $("#<%=TextBox1.ClientID%>").autocomplete({ minLength: 4 });
      $("#<%=TextBox1.ClientID%>").autocomplete("option", "minLength", 4); 
      $("#<%=TextBox1.ClientID%>").autocomplete("AutocompleteData.ashx");
      });
  </script> 

<%@ WebHandler Language="C#" Class="AutocompleteData" %>

using System;
using System.Web;
using System.Data.SqlClient;

public class AutocompleteData : IHttpHandler {

public void ProcessRequest(HttpContext context)
{
    string schoolname = context.Request.QueryString["q"];
    string sql = "my query";
    using (SqlConnection connection = new SqlConnection(
        System.Configuration.ConfigurationManager.ConnectionStrings["myConnectionString"].ConnectionString))
    using (SqlCommand command = new SqlCommand(sql, connection))
    {
        connection.Open();
        using (SqlDataReader reader = command.ExecuteReader())
        {
            while (reader.Read())
            {
                context.Response.Write(reader.GetString(0) + Environment.NewLine);
            }
        }
    }
}

public bool IsReusable {
    get {
        return false;
    }
}
}
4

1 に答える 1