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 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:

    Hope it will be helpful to you.

    Pawan Awasthi(DNS MVM)
    +91 8123489140 (whatsApp), +60 14365 1476(Malaysia)

  • #768897

    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

    public static List GetEmpNames(string prefixText)
    SqlConnection con = new SqlConnection("DataBase=ENGSOFT;User id=sa;Password=P@ssword9");
    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();

    List Empname = new List();

    for (int i = 0; i < dt.Rows.Count; i++)
    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.

    Hope this helps you...

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

    Blog :

  • #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.

    Blog :

  • #768937
    You can use this code Snippet to create AutoComplete Textbox in Windows Application using C#
     AutoCompleteStringCollection collection = new AutoCompleteStringCollection();
    string connectionString="your connection string";
    SqlConnection con = new SqlConnection(connectionString);
    SqlDataAdapter ad = new SqlDataAdapter("select sname from tbl_Student", con);
    DataTable dt = new DataTable();
    for (int i = 0; i < dt.Rows.Count; i++)

    textBox1.AutoCompleteMode = AutoCompleteMode.Suggest;
    textBox1.AutoCompleteSource = AutoCompleteSource.CustomSource;
    textBox1.AutoCompleteCustomSource = collection;

  • #769325
    Hi Nadeem

    please see my article published on same:

    Anjali Bansal

    ~Give your best and lead the world

  • Sign In to post your comments