I am using the jQuery autocomplete plugin. Not jQueryUI autocomplete. I can't seem to find any good instructions on jQuery autocomplete.
Does anyone know how to get multiple search parameters and results.
ie. User can search either ID, FNAME, LNAME and the autocomplete shows the results accordingly?
So search JON auto complete returns JON DOE N41, JONATHAN MILLER Q66
or
Search Q6 auto complete returns JONATHAN MILLER Q66, MIKE CAMPBELL Q67, etc
Here is my current code.
ashx handler:
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.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"])
.Append(Environment.NewLine);
}
}
conn.Close();
context.Response.Write(sb.ToString());
}
}
}
public bool IsReusable {
get {
return false;
}
}
}
And here is my HTML:
<script src="Scripts/jquery.autocomplete.js" type="text/javascript"></script>
<link href="Autocomplete/jquery.autocomplete.css" rel="stylesheet" type="text/css" />
<script type="text/javascript">
$(document).ready(function() {
$("#<%=txtSearch.ClientID%>").autocomplete('Autocomplete/Search_CS.ashx', {width: 400, multiple: true, matchContains: true });
});
</script>