Click here to Skip to main content
15,891,607 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am quite new to JQuery and I want to use the autocomplete populate text in a textbox but I can't find an example where data is being taken from sql database,and it been populate into the textbox control. Does anybody have a simple example?
Posted
Updated 4-Jun-12 2:34am
v6
Comments
Prasad_Kulkarni 4-Jun-12 8:31am    
Which database? tag it properly so you can get quick and appropriate response.

var tem = new Array();

$(function () {

$("#txtClientName").autocomplete({
source: function (request, response) {

$.ajax({

url: "url",
type: "POST",
dataType: "json",

data: { searchText: request.term, maxResults: 10 },
success: function (data) {

if (data.toString() != "No Record Found") {
var i = 0;

response($.map(data, function (item) {

// $('#txtName').val(item.strUserName);
tem[i] = item.Text;
i++;
return { label: item.Text, id: item.Value }
}))

}
}
})
},
select: function (event, ui) {

//alert(ui.item ? (ui.item.label +"You picked '" + ui.item.label + "' with an ID of " + ui.item.id): "Nothing selected, input was " + this.value);

$('#txtClientName').val(ui.item.label);


}

});

});
on controller:-
SQL
public JsonResult getClientName(string searchText)
             {


HomeModel mgrObj = new HomeModel();
SortedList lstObj = new SortedList();

//connect to data base query.and return list
return Json(slst);
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900