Hi,
Please refer below code.
HTML
<div>
<asp:TextBox ID="txtCountry" runat="server" />
<asp:HiddenField ID="hfCountries" runat="server" />
<link rel="stylesheet" href='http://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.0.3/css/bootstrap.min.css'
media="screen" />
<script type="text/javascript" src='http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.8.3.min.js'></script>
<script type="text/javascript" src='http://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.0.3/js/bootstrap.min.js'></script>
<script type="text/javascript" src="http://cdn.rawgit.com/bassjobsen/Bootstrap-3-Typeahead/master/bootstrap3-typeahead.min.js"></script>
<link rel="Stylesheet" href="https://twitter.github.io/typeahead.js/css/examples.css" />
<script type="text/javascript">
$(function () {
$('[id*=txtCountry]').typeahead({
hint: true,
highlight: true,
minLength: 1,
source: function (request, response) {
var txt = request;
items = [];
map = {};
var countries = $('[id*=hfCountries]').val();
$.each(countries.split(';'), function () {
var country = $(this)[0].split('-')
if ($(country)[1].toLowerCase().trim().indexOf(txt.toLowerCase().trim()) > -1) {
var id = $(country)[0];
var name = $(country)[1];
map[name] = { id: id, name: name };
items.push(name);
}
});
response(items);
$(".dropdown-menu").css("height", "auto");
},
updater: function (item) {
$('[id*=hfCustomerId]').val(map[item].id);
return item;
}
});
});
</script>
</div>
C#
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
List<string> countries = new List<string>()
{
string.Format("{0}-{1}",1,"India"),
string.Format("{0}-{1}",2,"Afganistan"),
string.Format("{0}-{1}",3,"Pakistan"),
string.Format("{0}-{1}",4,"Tajkistan"),
string.Format("{0}-{1}",5,"Turkmanistan")
};
hfCountries.Value = string.Join(";", countries);
}
}
Screenshot