In this code snippet, I have shared the code to work with Auto complete extender using web service method
Aspx code.
<ap:AutoCompleteExtender ServiceMethod="SearchCustomers" ServicePath="~/Address_WebService.asmx"
MinimumPrefixLength="2"
CompletionInterval="100" EnableCaching="false" CompletionSetCount="10"
TargetControlID="txtContactsSearch"
ID="AutoCompleteExtender1" runat="server" FirstRowSelected = "false">
</ap:AutoCompleteExtender>
<asp:TextBox ID="txtContactsSearch" runat="server"></asp:TextBox>
Webservice code[WebMethod]
public static List<string> SearchCustomers(string prefixText, int count)
{
using (SqlConnection conn = new SqlConnection())
{
conn.ConnectionString = ConfigurationManager
.ConnectionStrings["Webconfig_Con"].ConnectionString;
using (SqlCommand cmd = new SqlCommand())
{
cmd.CommandText = "select * from tblCustomer where CompanyName like '%" + prefixText + "%' ";
cmd.Connection = conn;
conn.Open();
List<string> customers = new List<string>();
using (SqlDataReader sdr = cmd.ExecuteReader())
{
while (sdr.Read())
{
customers.Add(sdr["CompanyName"].ToString());
}
}
conn.Close();
return customers;
}
}
}