Sandeep Shekhawat

Sandeep Shekhawat

  • 913
  • 859
  • 908.1k

How can use autocompleteextender of ajax control toolkit using web service.

Dec 30 2010 2:12 AM
my aspx page is auto.aspx

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>

<form id="form1" runat="server">
            <cc1:ToolkitScriptManager ID="ToolkitScriptManager1" EnablePageMethods="true" runat="server">
           
        </cc1:ToolkitScriptManager>
        <div>
<asp:TextBox ID="txtcon" runat="server"></asp:TextBox>
            <cc1:AutoCompleteExtender ID="txtcon_AutoCompleteExtender" runat="server" 
                TargetControlID="txtcon"
                ServicePath="Countries.asmx" 
                ServiceMethod="GetCompletionList"
                MinimumPrefixLength="1"
                CompletionInterval="1000"
                EnableCaching="true"
                CompletionSetCount="20"
                >
            </cc1:AutoCompleteExtender>
    </div>
    </form>

and 


web service is Countries.asmx is

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Xml.Linq;
using AjaxControlToolkit;
using System.Data.SqlClient;
using System.Configuration;
using System.Collections.Generic;
using System.Collections.Specialized;

namespace AutocompleteExample
{
    /// <summary>
    /// Summary description for Countries
    /// </summary>
[WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [ToolboxItem(false)]
    // To allow this Web Service to be called from script, using ASP.NET AJAX,          //uncomment the following line. 
     [System.Web.Script.Services.ScriptService]
    public class Countries : System.Web.Services.WebService
    {
   [WebMethod]
        [System.Web.Script.Services.ScriptMethod]

        public string[] GetCompletionList(string prefixTest,int count)
        {
            string connStr = ConfigurationManager.ConnectionStrings["san"].ConnectionString;
            SqlDataAdapter cmd1 = new SqlDataAdapter("select * from tbl_country where country_name like '" + prefixTest + "%'", connStr);
            DataSet ds2 = new DataSet();
            cmd1.Fill(ds2, "countries");
            DataTable dt1 = ds2.Tables["countries"];
            List<string> country = new List<string>(10);
   
            foreach (DataRow dr in dt1.Rows)
            {
                country.Add(dr["country_name"].ToString());
                
            }
            return country.ToArray();
        }
    }

It is not show any error but web service individual method run but it can not call by .aspx page  Textbox when press any char
please solve my problems

Thanx 

Answers (1)