Google Type Textbox Auto bind value using Web services

First of all add AjaxControlToolKit reference


 <%@ Register Assembly="AjaxControlToolkit"Namespace="AjaxControlToolkit"
TagPrefix="cc1"%>

JavaScript for load image

 <script type="text/javascript">
function ShowIcon() {

var e = document.getElementById("loading");
e.style.visibility = (e.style.visibility == 'visible') ? 'hidden' : 'visible';
}
</script>

Design Code

 <asp:ScriptManager ID="ScriptManager1" EnablePageMethods="true" runat="server">
</asp:ScriptManager>
<asp:TextBox ID="txtemployee" runat="server" Width="40%" Height="15px" OnTextChanged="txtemployee_TextChanged"></asp:TextBox>
<img id="loading" style="visibility: hidden" src="IMAGES/ajax-loader.gif" />
<cc1:AutoCompleteExtender ID="AutoCompleteExtender1" runat="server" EnableCaching="true"
TargetControlID="txtemployee" ServiceMethod="GetCities" ServicePath="WebService.asmx"
OnClientPopulating="ShowIcon" OnClientPopulated="ShowIcon" MinimumPrefixLength="1"
CompletionSetCount="10" FirstRowSelected="true">

Web service Function Code

 using System;
using System.Collections;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Xml.Linq;
using System.Data.SqlClient;
using System.Data;
using System.Collections.Generic;
[System.Web.Script.Services.ScriptService]
public class WebService : System.Web.Services.WebService
{
[WebMethod]
public string[] GetCities(string prefixText)
{
SqlConnection con = new SqlConnection("Data Source=BITPLUS5\\SqlExpress;Initial Catalog=WEBHR_22112011;User ID=sa;pwd=bit123;");

con.Open();
string strQuery = "select emp_name from tblemployee where emp_name like '" + prefixText + "%'";

DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter(strQuery, con);
da.Fill(ds);
con.Close();
List<string> cityList = new List<string>();
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
cityList.Add(ds.Tables[0].Rows[i][0].ToString());
}
con.Close();
return cityList.ToArray();
}
}