Click here to Skip to main content
15,895,709 members
Articles / Web Development / HTML

AutoCompelete Control Extender with With DB

Rate me:
Please Sign up or sign in to vote.
1.00/5 (1 vote)
30 Mar 2008CPOL 21.3K   306   15  
AutoCompelete Control Extender with With DB
  • test_project.zip
    • Test Project
      • App_Code
      • App_Data
      • App_Themes
        • DefaultTheme
          • Default.skin
          • images
            • album-bstretch.gif
            • album-l1.gif
            • album-l2.gif
            • album-l3.gif
            • album-l4.gif
            • album-lstretch.gif
            • album-mbl.gif
            • album-mbr.gif
            • album-mtl.gif
            • album-mtr.gif
            • album-r1.gif
            • album-r2.gif
            • album-r3.gif
            • album-r4.gif
            • album-rstretch.gif
            • album-tstretch.gif
            • background.gif
            • background1.gif
            • background-green.gif
            • body-repeat.gif
            • body-repeat-photo.gif
            • bullet-1.gif
            • bullet-2.gif
            • button-add.gif
            • button-cancel.gif
            • button-create.gif
            • button-delete.gif
            • button-download.gif
            • button-dwn_res.gif
            • button-edit.gif
            • button-first.gif
            • button-gallery.gif
            • button-import.gif
            • button-insert.gif
            • button-last.gif
            • button-login.gif
            • button-next.gif
            • button-play.gif
            • button-prev.gif
            • button-rename.gif
            • button-save.gif
            • button-tog24.gif
            • button-tog8.gif
            • collapse.jpg
            • collapse_blue.jpg
            • content-shim.gif
            • content-shim-none.gif
            • content-shim-photo.gif
            • content-shim-stretch.gif
            • expand.jpg
            • expand_blue.jpg
            • footer.gif
            • footer-side.gif
            • frame-botx--.gif
            • frame-bot-x-.gif
            • frame-bot--x.gif
            • frame-midx--.gif
            • frame-mid--x.gif
            • frame-topx--.gif
            • frame-top-x-.gif
            • frame-top--x.gif
            • header.gif
            • login.gif
            • Logo.gif
            • photonav-bg.gif
            • photonav-top-bg.gif
            • SearchImage.gif
            • spacer.gif
            • Thumbs.db
          • StyleSheet.css
          • ve-21.tmp
      • AutoComplete.asmx
      • AutoComplete.aspx
      • AutoComplete.aspx.cs
      • Bin
        • AjaxControlToolkit.dll
        • AjaxControlToolkit.dll.refresh
        • AjaxControlToolkit.pdb
      • Default.aspx
      • Default.aspx.cs
      • Web.config
using System;
using System.Web;
using System.Collections;
using System.Collections.Generic;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Data;
using System.Data.SqlClient;
using System.Configuration; 

[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.Web.Script.Services.ScriptService]
public class AutoComplete : WebService
{
    string connectionString = string.Empty;
    DataTable dt = null;
    SqlCommand objCommnad = null;
    SqlDataAdapter da = null;
    SqlConnection con = null;
    public AutoComplete()
    {
    }

    [WebMethod]
    public string[] GetCompletionList(string prefixText, int count)
    {
        if (count == 0)
        {
            count = 10;
        }

        if (prefixText.Equals("xyz"))
        {
            return new string[0];
        }

        Random random = new Random();
        List<string> items = new List<string>(count);
        for (int i = 0; i < count; i++)
        {
            char c1 = (char)random.Next(65, 90);
            char c2 = (char)random.Next(97, 122);
            char c3 = (char)random.Next(97, 122);

            items.Add(prefixText + c1 + c2 + c3);
        }

        //return items.ToArray();

        return getCompany(prefixText); 

        /////////////////Rizwan Code Here \\\\\\\\\\\\\\\\\\\\\\\

    }
    private string[] getCompany(string CompanyNameLike)
    {
        connectionString = ConfigurationManager.AppSettings["ConStr1"].ToString();
        con = new SqlConnection(connectionString);
        try
        {
            con.Open();
            objCommnad = new SqlCommand();
            objCommnad.Connection = con;
            objCommnad.CommandType = CommandType.StoredProcedure;
            objCommnad.CommandText = "LU_Select_ProPerty";
            objCommnad.Parameters.Add("@CompanyName", SqlDbType.VarChar).Value = CompanyNameLike;
            da = new SqlDataAdapter(objCommnad);
            dt = new DataTable();
            da.Fill(dt);
            //return dt;
        }
        catch (Exception ex)
        {
            con.Close();
            throw ex;
        }
        finally
        {
            con.Close();
        }
        List<string> items = new List<string>(dt.Rows.Count);
        for (int i = 0; i < dt.Rows.Count; i++)
        {
            items.Add(dt.Rows[i]["pro_name"].ToString());     
        }
        return items.ToArray() ;
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

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


Written By
Software Developer (Senior) Axact Pvt Ltd
Pakistan Pakistan
Sr Software Engineer
Axact Pvt Ltd
Karachi Pakistan

Comments and Discussions