Loading ...

How to implement autoextender for google suggest like functionality | CodeAsp.Net

How to implement autoextender for autosuggest textbox

0 (0votes)

I have seen that lot of my friends having problem in implementing the autoextender.

so that i have tried to describe that how to implement it.it may make easier to implement autoextender.

Step1:Add required controls

  • Add a text box from your toolbox.
  • Add a autoextender and set the TargetControlID of it by setting the id of above textbox.for eg.

<asp:TextBox ID="txtname" runat="server"/>

<ajaxToolkit:AutoCompleteExtender ID="aceName" Enabled="true" runat="server" MinimumPrefixLength="1" TargetControlID="txtname" CompletionSetCount="20" CompletionInterval="0000" EnableCaching="true"

ServiceMethod="GetName" ServicePath="AutoExtender.asmx"/>

Note: please make sure you have given the virtual path of web service and name of web method correctly.

Step2:Create the web service

 public class AutoExtender : System.Web.Services.WebService

public string[] GetName(string prefixText)

List<string> listString = new List<string>();
using (SqlConnection con = new SqlConnection("Initial Catalog=Dbname;Server=.;User ID=sa;Password=pwd"))
SqlCommand cm = new SqlCommand("SELECT Name,ID FROM tblUser Where Name like '" + prefixText + "%'", con);
SqlDataReader dr = cm.ExecuteReader();
if (dr.HasRows)
while (dr.Read())
listString.Add(AutoCompleteExtender.CreateAutoCompleteItem(dr["Name"].ToString(), dr["ID"].ToString()));

//c.FullName, serializer.Serialize(c))
string[] str = listString.ToArray();
return str;




Hope this will help..

Comments (2)

Very helpful blog!!
Hi. In your above example i want little modification.
I want to show only name in textbox with the help of autoextender control and not id. but it also retrives id so that i can use it.

Top Posts