Click here to Skip to main content
15,891,529 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
how to create autocompete extender with multiple word in ajax,
for example in Ask question page of codeproject Tags textbox in which multiple words fetch from database.

help me plz for this.
Posted

 
Share this answer
 
Comments
aarohi verma 16-May-12 6:44am    
Thanks, its solve my problem.links help me so much.
sunandandutt 30-May-12 5:58am    
Welcome Aarhoi Verma!
1.Add the AjaxControlToolkit.dll to your project(by Add Reference).
2.Register it in to Web.Config file.
EX:<add namespace="AjaxControlToolkit" assembly="AjaxControlToolkit" tagprefix="ajaxToolkit">
3.R.Click on your prject-->Add New Items-->Chooes-->Web Service-->AutoComplete.asmx(put name)

4.Then AutoComplete.asmx and AutoComplete.cs file is created.The

AutoComplete.cs is created on App Code .
5.Inside the AutoComplete.cs write the code and uncomment the line
as [System.Web.Script.Services.ScriptService]

EX:
C#
using System;
using System.Web;
using System.Collections;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Text;
using System.Web.Script.Services;

/// <summary>
/// Summary description for AutoComplete
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
//[System.Web.Script.Services.ScriptService]
[System.Web.Script.Services.ScriptService]
public class AutoComplete : System.Web.Services.WebService
{
      [WebMethod]

    public string[] GetBlocks(string prefixText)
    {
        DataSet dtst = new DataSet();  
        SqlConnection sqlCon = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ToString());
        string strSql = "select BlockName  from BlockMaster  WHERE ltrim(rtrim(BlockName))  LIKE '%" + prefixText + "%' and DeletedFlag=0  ";
        SqlCommand sqlComd = new SqlCommand(strSql, sqlCon);
        sqlCon.Open();
        SqlDataAdapter sqlAdpt = new SqlDataAdapter();
        sqlAdpt.SelectCommand = sqlComd;
        sqlAdpt.Fill(dtst);
        string[] BlockName = new string[dtst.Tables[0].Rows.Count];
        int i = 0;
        try
        {
            foreach (DataRow rdr in dtst.Tables[0].Rows)
            {
                BlockName.SetValue(rdr["BlockName"].ToString(), i);
                i++;
            }
        }
        catch { }
        finally
        {
            sqlCon.Close();
        }
        return BlockName;

}
6.Go to View or Search Page like Block.aspx

XML
<asp:TextBox ID="txtBlockSearch"  runat="server" CssClass="txtSearchBox"
              Width="200px"></asp:TextBox>


7.Write Inline code for AutoComplete Extender

XML
<ajaxToolkit:AutoCompleteExtender  runat="server" ID="autoComplete1" TargetControlID="txtBlockSearch" ServicePath="AutoComplete.asmx" ServiceMethod="GetBlocks" MinimumPrefixLength="1" EnableCaching="true">
   </ajaxToolkit:AutoCompleteExtender>


8.Run the project
 
Share this answer
 
v2
Comments
Wendelius 16-May-12 17:05pm    
Good answer!

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900