This is the jquery code:
$("#txt1").autocomplete({ source: function (request, response){ $.ajax({ type: "POST", url: "YourAddress", contentType: "application/json; charset=utf-8", dataType: "json", success: function (data) { response($.map(data.d, function (item) { return { id: item.Value, value: item.Text } })) } }); }, select: function (event, ui) { $("#hdnId").val(ui.item.id);
call the ajax request and return the JSON data like this:
[{"Value":val1,"Text":"text1"}, {"Value":val2,"Text":"text2"}]
to return somthing like this, you must define the class as follows:
public class Autocomplete { private int val; private string text; public int Value { get { return val; } set { val = value; } } public string Text { get { return text; } set { text = value; } } }
so this is enough to return a list of these class objects ( List<Autocomplete> ). Create this list and populate it with sqlcommand and then return it as a response from your XMLHTTPRequest
I tested it. It works great.
Good luck .Foroughi
source share