Implementing Google Suggestions using Ajax in ASP.Net 2.0

Tuesday, August 19, 2008
  • Using Ajax AutoComplete Extender we can Implement google suggestions like Applications.


  • This functionality is very simple, just we have to communicate with Webservice. Where we write the logic retrieve information from the database


  • To Webservice method we have to pass "prefixText" as parameter.


  • To Satrt this Application First we have to take a TextBox and make the TextBox "AutoComplete: option as "off". Ex:
    asp:TextBox ID="txtemp" runat="server" autocomplete="off".


  • Then take a "AutoCompleteExtender" For this use fallowing Properties. Ex:


  • TargetControlID="txtemp"


  • ServicePath="AutoCom.asmx"


  • ServiceMethod="GetEmpnames"


  • MinimumPrefixLength="1"


  • CompletionInterval="1000"


  • EnableCaching="true"


  • Thts it..for Presentation side.


  • Now create a Webservice, with name "AutoCom.asmx". In that one create a method as "GetEmpnames".


  • In this method we have to write the data access logic. here I used Sql Server as Database. Here is my code:


  • public string[] GetEmpnames(string prefixText) {


  • Open connection


  • SqlCommand cmd = new SqlCommand("select EmpName from Tbl_Emp where Empname like '" + prefixText + "%'", con);


  • SqlDataReader dr; dr = cmd.ExecuteReader();


  • List items = new List();


  • while (dr.Read())


  • {


  • items.Add(dr[0].ToString());


  • }


  • return items.ToArray();


  • }


  • Here is the Screenshot:

    Download Code
















1 comments:

Unknown said...

Hi Ramky,I See Your Blog is good for Programmers.I've Problem in my Application on Sending SMS.I use nowsms Gateway/services to send sms.
Problem is I've DHCP/DNS Dynamic Internet Connection so,No any Private IP or Host.In nowsms Gateway provide hostname and port.
So,How should I resolve Problem?
Please suggest me and reply me on my Emil-Id ankurpatelp@yahoo.co.in