1
I have a text field in the sql server database varchar (MAX).
I am using Jquery and C# to make an autocomplete.
This is populated through a "autocomplete.ashx" file called by jqyery.
My field in the database is formed by a string that is mounted dynamically in levels that are divided by the special character "\".
String example (filename field): "first level second third fourth fifth"
The table consists basically of the following fields: Id, Full Name, Level
Given the scenario what I need is for the autocomplete to work as follows:
When clicked without typing anything appear only the records of the first level, when the selection of the first level automatically the autocomplete appears with the second level options within the first level, when selected the second level appear the records of the third level and so on.
It is currently working as a normal autocomplete, taking any part of the full string.
public class ContaAutoComplete : IHttpHandler, IReadOnlySessionState
{
public void ProcessRequest(HttpContext context)
{
var nomeCompleto = context.Request.QueryString["term"];
var contas = Conta.ObterVarios(idCliente: MySession.Cliente.Id, nomeCompleto: nomeCompleto)
.Select(x => new
{
value = x.NomeCompleto,
label = x.NomeCompleto
});
using (var jsonWriter = new JsonTextWriter(context.Response.Output))
{
var serializer = new JsonSerializer();
serializer.Serialize(jsonWriter, contas);
}
}
public bool IsReusable
{
get
{
return true;
}
}
}
<script type="text/javascript">
$(function () {
$("#<%=txtContaAutoComplete.ClientID%>").autocomplete({
source: 'ContaAutoComplete.ashx',
minLength: 0
}).focus(function () {
$(this).autocomplete("search", "");
});
});
</script>