我使用的是jQuery Autocomplete,而不是jQueryUI,目前它不会显示超过10个结果。我已经指出max:20尝试一下但无济于事。是因为我的查询限制吗?
的Javascript
$(document).ready(function() {
$("#<%=txtSearch.ClientID%>").autocomplete('Autocomplete/Search_CS.ashx', {width: 400, multiple: false, matchContains: true, delay: 200, Max: 20 });
});
ASHX
public class Search_CS : IHttpHandler {
public void ProcessRequest (HttpContext context) {
string prefixText = context.Request.QueryString["q"];
using (SqlConnection conn = new SqlConnection())
{
conn.ConnectionString = ConfigurationManager
.ConnectionStrings["Rollup2ConnectionString"].ConnectionString;
using (SqlCommand cmd = new SqlCommand())
{
//cmd.CommandText = "select NUID from T_USER where " +
//"NUID like @SearchText + '%'";
cmd.CommandText = "select rtrim(NUID) NUID, rtrim(FNAME) FNAME, rtrim(LNAME) LNAME from T_USER where NUID like @SearchText + '%' OR FNAME like @SearchText + '%' OR LNAME like @SearchText + '%'";
cmd.Parameters.AddWithValue("@SearchText", prefixText);
cmd.Connection = conn;
StringBuilder sb = new StringBuilder();
conn.Open();
using (SqlDataReader sdr = cmd.ExecuteReader())
{
while (sdr.Read())
{
sb.Append(sdr["NUID"].ToString() + " ").Append(sdr["FNAME"].ToString() + " ").Append(sdr["LNAME"].ToString() + " ")
.Append(Environment.NewLine);
}
}
conn.Close();
context.Response.Write(sb.ToString());
}
}
}
public bool IsReusable {
get {
return false;
}
}
}
答案 0 :(得分:1)
其max
而非Max
$("#<%=txtSearch.ClientID%>").autocomplete('Autocomplete/Search_CS.ashx', {width: 400, multiple: false, matchContains: true, delay: 200, max: 20 });