AJAX AutoComplete with DataSet

/// <summary>

/// This webservice is used with AJAX AutoComplete Extender

/// to populate possible car makes for textbox on Sell Your Car form

/// </summary>

[ScriptService()]

[WebService(Namespace = "http://tempuri.org/")]

[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]

[ToolboxItem(false)]

public class MakeAutoComplete : System.Web.Services.WebService

{

 

    [WebMethod]

    [ScriptMethod()]

    public string[] GetNames(string prefixText, int count)

    {

        ArrayList sampleList = new ArrayList();

        DataSet ds = null;

        SAS sas = new SAS();

        DataFactory factory = new DataFactory();

 

        ds = sas.GetUsedMakes(factory.dbConnection);

 

 

        for (int i = 0; i < ds.Tables[0].Rows.Count; i++)

        {

            sampleList.Add(ds.Tables[0].Rows[i]["make"]);

 

        }           

 

 

        ArrayList filteredList = new ArrayList();

        foreach (string s in sampleList)

        {

 

            if (s.ToLower().StartsWith(prefixText.ToLower()))

 

                filteredList.Add(s);

 

        }

        return (string[])filteredList.ToArray(typeof(string));

 

    }

}

 

<asp:TextBox ID="txtMake" runat="server" CssClass="textbox"></asp:TextBox>

<cc1:AutoCompleteExtender

ID="ACEMake"

runat="server"

TargetControlID="txtMake" 

Enabled="true"

EnableCaching="true"

MinimumPrefixLength="1"

ServiceMethod="GetNames"

ServicePath="../MakeAutoComplete.asmx" />

No Comments