My asp Code using jquery autocomplete to call method GetCities
<div><h1>AutoComplete Textbox</h1>
City:
<asp:TextBox ID="txtCity" Width="403px" runat="server"></asp:TextBox>
<script type="text/javascript">
$(function () {
$("#txtCity").autocomplete({
source: function (request, response) {
var param = { cityName: $('#txtCity').val() };
$.ajax({
url: "/WebForm1.aspx/GetCities",
data: JSON.stringify(param),
dataType: "json",
type: "POST",
contentType: "application/json; charset=utf-8",
dataFilter: function (data) { return data; },
success: function (data) {
response($.map(data.d, function (item) {
return {
value: item.name,
url: item.img
}
}))
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
alert(textStatus);
}
});
},
minLength: 1
})
.data("ui-autocomplete")._renderItem = function (ul, item) {
var bla = $('#txtCity').val();
var inner_html = '<a><div class="list_item_container"><div class="image" style=\"float:left;\"><img style=\"height: 80px;\" src="' + item.url + '"></div><div style=\"word-break: break-all;padding-left: 40%; padding-top: 7%\">' + item.value + '</div></div><div style=\"clear:both;\"></div></a>';
var bottom_htm = '<hr>View all results for "' + bla + '"'
return $("<li></li>")
.data("item.autocomplete", item)
.append(inner_html)
.appendTo(ul);
};
});
</script>
and my code behide return a list card
[WebMethod]
public static List<Card> GetCities(string cityName)
{
List<Card> cities = new List<Card>();
cities.Add(new Card("MACY'S EGIFT CARD", "http://static2.cardlabcorp.com/Product+images/eGift/Macys-GCM.jpg"));
cities.Add(new Card("TARGET EGIFT CARD", "http://static2.cardlabcorp.com/Product+images/eGift/Target-GCM.png"));
cities.Add(new Card("TARGET EGIFT CARD", "http://static2.cardlabcorp.com/Product+images/eGift/Target-GCM.png"));
cities.Add(new Card("TARGET EGIFT CARD", "http://static2.cardlabcorp.com/Product+images/eGift/Target-GCM.png"));
cities.Add(new Card("TARGET EGIFT CARD", ""));
if(string.IsNullOrEmpty(cityName)) return cities;
return cities.Where(x => x.name.ToUpper().Contains(cityName.ToUpper())).ToList();
}
i want to add bottom_htm into footer of dropdown list autocomplete but i don't know how to do it pls help me to solve this problem, thanks for advance.