Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# ASP.NET .NET Ajax
Hello, Can anyone please help me out with the autocomplete textbox code, Which uses c# and Ajax. I'm very much confused of developing it.
Posted 6-Jun-12 20:13pm
Comments
Arjun YK at 7-Jun-12 7:29am
   
Use this link for the solution http://www.dotnetfunda.com/articles/article224.aspx. and just replace the Script Manager tool with Tool Script Manager. Enjoy The Output......May be u have to change the like Clause also if needed in my case i used it as '@Name'
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

You can either use XMLHttpRequest or using AJAX controls.
 
Below are demo for AJAX control AutoCompleteExtender:

Using Ajax AutoCompleteExtender for autosuggest[^]
 
XMLHTTPRequest:
 
Google-Like-Search-TextBox
  Permalink  
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

You can use XMLHttpRequest object[^]
also,
You can use jQuery for same.
Plugins/Autocomplete[^]
UI/API/1.8/Autocomplete[^]
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 7

Autucomplete without using web service It should help you.-->Test.aspx(html code)
<form id="form1" runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true">
    </asp:ScriptManager>
    <div>
    <table>
        <tr>
            <td>
            <asp:TextBox ID="txtContactsSearch" runat="server"></asp:TextBox>
                <asp:AutoCompleteExtender ID="txtContactsSearch_AutoCompleteExtender"
                    runat="server" ServiceMethod="Getdata"  MinimumPrefixLength="1" CompletionInterval="1000"
                    EnableCaching="true" CompletionSetCount="1"
                    TargetControlID="txtContactsSearch" UseContextKey="True" >
                    </asp:AutoCompleteExtender>
            </td>
        </tr>
    </table>
    </div>
    </form>
 
Code behind -->Test.aspx.cs
 
[System.Web.Services.WebMethodAttribute(),System.Web.Script.Services.ScriptMethodAttribute()]
    public static List<string>  Getdata(string prefixText, int count, string contextKey)
    {
       //Make your database connection here
       string strSQL = "SELECT * FROM YourTable WHERE coloumnName Like '" + prefixText + "%'";
       //Get data in datatable 

        List<String> list = new List<String>();
        foreach(DataRow dr in dataTable.Rows)
        {
            list.Add(dr["coloumnName "].ToString());
        }
        return list;
    }
  Permalink  
v3
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 5

Hi
you can also use this jQuery http://jqueryui.com/demos/autocomplete/[^] plugin along with a web service
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 6

Visit The Following link you will be getting your problem solutions.Using Ajax AutoCompleteExtender for autosuggest[^]
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 8

This is my aspx File
<asp:ImageButton ID="frumgrp_srch_imgbtn" runat="server" ImageUrl="~/images/search.png" />
                    &nbsp;&nbsp;&nbsp;&nbsp;<br />
                    <asp:AutoCompleteExtender ID="AutoCompleteExtender1" runat="server" TargetControlID="frumgrp_srch_txt"
                                 EnableCaching="true"
       BehaviorID="AutoCompleteCities"
       ServiceMethod="GetCities" ServicePath="~/AutoComplete.asmx"  MinimumPrefixLength="1"      CompletionSetCount="5"
        FirstRowSelected="true">
        </asp:AutoCompleteExtender>
 
This Is My Cs File
using System;
using System;
using System.Collections.Generic;
using System.Web.Services;
using System.Data.SqlClient;
using System.Configuration;
using System.Data;
 
[WebService]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.Web.Script.Services.ScriptService]
public class AutoComplete : WebService
{
    public AutoComplete()
    {
    }
 
    [WebMethod]
    public string[] GetCompletionList(string prefixText, int count)
    {
        if (count == 0)
        {
            count = 10;
        }
        DataTable dt = GetRecords(prefixText);
        List<string> items = new List<string>(count);
 
        for (int i = 0; i < dt.Rows.Count; i++)
        {
            string strName = dt.Rows[i][0].ToString();
            items.Add(strName);
        }
        return items.ToArray();
    }
 
    public DataTable GetRecords(string strName)
    {
        string strConn = ConfigurationManager.ConnectionStrings["DatabaseConnectionString"].ConnectionString;
        SqlConnection con = new SqlConnection(strConn);
        SqlCommand cmd = new SqlCommand();
        cmd.Connection = con;
        cmd.CommandType = System.Data.CommandType.Text;
        cmd.Parameters.AddWithValue("@Name", strName);
        cmd.CommandText = "Select Name from Test where Name like '%'+@Name+'%'";
        DataSet objDs = new DataSet();
        SqlDataAdapter dAdapter = new SqlDataAdapter();
        dAdapter.SelectCommand = cmd;
        con.Open();
        dAdapter.Fill(objDs);
        con.Close();
        return objDs.Tables[0];
 

 

 
    }
}
 

 

This is My asmx File
<![CDATA[<%@ WebService Language="C#" CodeBehind="~/App_Code/AutoComplete.cs" Class="AutoComplete" %>
 
I'm not able to execute this code. Infact the webservice it self is not getting called. Can Anyone help. Your help will be a great relief to me.
Eagerly Waiting For The Solution
Thanks in advance
  Permalink  
v3
Comments
Member 10337869 at 26-Jan-14 23:49pm
   
your in ServiceMethod="GetCities" is not present in cs file .It should be GetCompletionList
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 10

I Know you already got the answer from all previous posts,
But here am providing you easy way to know about the Ajax Autocomplete control
 
Videos:
 
www.youtube.com/watch?v=2i50R-fHHlA[^]
www.youtube.com/watch?v=nYac4sxChdk[^]
 

Thanks
--RA
  Permalink  
Comments
Arjun YK at 8-Jun-12 6:15am
   
Thank U
Rajesh Anuhya at 8-Jun-12 7:42am
   
Vote or Accept Answer if it's helpful to you
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 12

hi
 
i hope it will you
Auto complete text box using ajax[^]
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 9

Use this link for the solution http://www.dotnetfunda.com/articles/article224.aspx. and just replace the Script Manager tool with Tool Script Manager. Enjoy The Output......May be u have to change the like Clause also if needed in my case i used it as '+@Name+'
  Permalink  
v3
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 13

Hi
 

Make sure that the function / or Service method lies in Aspx page, not in a control of course.
  Permalink  
Comments
nika2008 at 13-Jun-13 11:56am
   
check data before you give Solution

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 575
1 Kornfeld Eliyahu Peter 409
2 Maciej Los 369
3 DamithSL 196
4 OriginalGriff 188
0 OriginalGriff 6,353
1 DamithSL 4,854
2 Maciej Los 4,476
3 Kornfeld Eliyahu Peter 4,058
4 Sergey Alexandrovich Kryukov 3,917


Advertise | Privacy | Mobile
Web03 | 2.8.141223.1 | Last Updated 10 Aug 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100