You must Sign In to post a response.
  • Category: Webservices

    Implement autocomplete in textbox based on Name column

    i want to add autocomplete feature to my textbox based on name column from database either using web services or ajax in asp.net web forms .
  • #768895
    Hai Nadeem,
    There are many example which you can find in our website for the implementation including the code. Below I am providing the links which you can refer for the implementation:

    http://www.dotnetspider.com/resources/30998-Creating-winforms-AutoComplete-TextBox-using-C.aspx
    http://www.dotnetspider.com/forum/310781-binding-id-text-autocomplete-textbox-from.aspx
    http://www.dotnetspider.com/resources/45209-Ajax-Auto-Complete-Without-WebServices-aspnet.aspx
    http://www.dotnetspider.com/forum/331591-Why-Textbox-autocomplete-not-working-first-character.aspx

    Hope it will be helpful to you.

    Regards,
    Pawan Awasthi(DNS MVM)
    +91 8123489140 (whatsApp), +60 14365 1476(Malaysia)
    pawansoftit@gmail.com

  • #768897
    Hi,

    If you want to implement without webservice and using AJAX, you may refer below piece of code, it's very simple and easy to implementation using AJAX controls.


    <ajaxToolkit:AutoCompleteExtender ID="autoExtender" runat="server" TargetControlID="txt1" ServiceMethod="GetEmpNames"
    MinimumPrefixLength="1" CompletionInterval="100" EnableCaching="false" CompletionSetCount="10"></ajaxToolkit:AutoCompleteExtender>


    and in source code use below piece of code

    [System.Web.Script.Services.ScriptMethod()]

    [System.Web.Services.WebMethod]

    public static List GetEmpNames(string prefixText)
    {
    SqlConnection con = new SqlConnection("DataBase=ENGSOFT;User id=sa;Password=P@ssword9");
    con.Open();
    SqlCommand cmd = new SqlCommand("select empno, ename,job,mgr,hiredate,sal,comm,picture from emp where ename like '%'+ @Name+'%'", con);
    cmd.Parameters.AddWithValue("@Name", prefixText);
    SqlDataAdapter da = new SqlDataAdapter(cmd);
    DataTable dt = new DataTable();
    da.Fill(dt);

    List Empname = new List();

    for (int i = 0; i < dt.Rows.Count; i++)
    {
    Empname.Add(dt.Rows[i]["ename"].ToString());
    }
    con.Close();
    return Empname;
    }


    and if you want to know how to register AJAX and how to configure to achieve your task then refer below link, here I explained clearly with step by step.

    http://www.dotnetspider.com/resources/45209-Ajax-Auto-Complete-Without-WebServices-aspnet.aspx

    Hope this helps you...

    --------------------------------------------------------------------------------
    Give respect to your work, Instead of trying to impress your boss.

    N@veen
    Blog : http://naveens-dotnet.blogspot.in/

  • #768898
    hai bro... from both the ways, which one is efficient to use..means with one is better to use for real time applications ,either a web service or using Ajax tools...

  • #768900
    Hi Mohammed,

    both are good options only but the great advantage of using AJAX means you can give more stylish to your application, if there is no separate UI designer to your project my suggestion is AJAX, in any case their is a UI designer then you need not worry about styling and all in that case webservice is the best option.

    Hope this helps you....

    --------------------------------------------------------------------------------
    Give respect to your work, Instead of trying to impress your boss.

    N@veen
    Blog : http://naveens-dotnet.blogspot.in/


Sign In to post your comments