Ref:
You need to change this code
HTML
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<style type="text/css">
body
{
font-family: Arial;
font-size: 10pt;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.10.0.min.js" type="text/javascript"></script>
<script src="http://ajax.aspnetcdn.com/ajax/jquery.ui/1.9.2/jquery-ui.min.js" type="text/javascript"></script>
<link href="http://ajax.aspnetcdn.com/ajax/jquery.ui/1.9.2/themes/blitzer/jquery-ui.css"
rel="Stylesheet" type="text/css" />
<script type="text/javascript">
$(function () {
$("[id*=txtSearch]").autocomplete({
source: function (request, response) {
if (request.term.indexOf('@') != -1) {
$.ajax({
url: 'Default.aspx/GetFruits',
data: "{ 'prefix': '" + request.term + "'}",
dataType: "json",
type: "POST",
contentType: "application/json; charset=utf-8",
success: function (data) {
if (data.d.length > 0) {
response($.map(data.d, function (item) {
return {
label: removeLast(request.term, item.split('-')[0]),
val: item.split('-')[1]
};
}))
} else {
response([{ label: 'No results found.', val: -1}]);
}
}
});
}
},
select: function (e, u) {
if (u.item.val == -1) {
return false;
}
}
});
});
function removeLast(str, autowords) {
return str.split('@')[0] + autowords;
}
</script>
Enter search term:
<input type="text" id="txtSearch" />
</form>
</body>
</html>
C#
[System.Web.Services.WebMethod]
[System.Web.Script.Services.ScriptMethod()]
public static string[] GetFruits(string prefix)
{
if (prefix.Contains("@"))
{
prefix = prefix.Replace("@", "");
List<string> fruits = new List<string>();
fruits.Add("Mango");
fruits.Add("Apple");
fruits.Add("Banana");
fruits.Add("Orange");
fruits.Add("Pineapple");
fruits.Add("Guava");
fruits.Add("Grapes");
fruits.Add("Papaya");
return fruits.Where(f => prefix.ToLower().Contains(f.ToLower().ToLower())).ToArray();
}
else
{
string[] stringData = new string[0];
return stringData;
}
}