HTML
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>AutoComplete Extender</title>
</head>
<body>
<form runat="server">
<div>
<b style = "color:Red;">Enter Customer Name</b>
<asp:TextBox ID="txtContactsSearch" runat="server"></asp:TextBox>
<asp:AutoCompleteExtender ID="txtContactsSearch_AutoCompleteExtender" MinimumPrefixLength="1"
ServiceMethod="SearchCustomers" CompletionInterval="100" EnableCaching="false"
CompletionSetCount="10" TargetControlID="txtContactsSearch" runat="server" FirstRowSelected="false">
</asp:AutoCompleteExtender>
<asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true">
</asp:ScriptManager>
</div>
</form>
</body>
</html>
CODE BEHIND
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
public partial class AutoCompleteExtender : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
private static List<Customer > GetStudent()
{
List<Customer > Customers = new List<Customer >()
{
new Customer {Name = "Roman"},
new Customer {Name = "Iqbal"},
new Customer { Name = "Amin"},
new Customer { Name = "Asad"},
new Customer { Name = "Abul"},
new Customer { Name = "Abaden"},
new Customer { Name = "M Ali"},
new Customer { Name = "Ashikur Rhaman"},
new Customer { Name = "Abdul"},
new Customer { Name = "Asif"},
new Customer { Name = "Aminur"},
new Customer { Name = "Arifur Rahman"},
new Customer { Name = "Asgor"},
new Customer { Name = "Abul Momen"}
};
return Customers;
}
public class Customer
{
public string Name { get; set; }
}
[System.Web.Services.WebMethodAttribute(), System.Web.Script.Services.ScriptMethodAttribute()]
public static List<string> SearchCustomers(string prefixText, int count)
{
List<Customer > CustomeList = GetStudent();
var query = from m in CustomeList
select m.Name.ToString();
try
{
return (from customer in query
where customer.ToLower().StartsWith(prefixText.ToLower())
select customer).Take (count).ToList<string>();
}
catch (Exception ex )
{
throw new Exception("Problem Loading in finding customer" + ex.Message);
}
}
}