Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3981658
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T05:26:11+00:00 2026-05-20T05:26:11+00:00

I am trying to create an autocomplete textbox using jquery which will be bound

  • 0

I am trying to create an autocomplete textbox using jquery which will be bound to SQL database. I also want to place a dropdownlist on the page so based on initial selection autocomplete textbox will retrieve data from different tables. It’s an ASP.NET 2.0 page and code behind is VB.NET. I have AJAX autocomplete working but it matches only first characters and its not as robust as jquery. Can anyone share a sample code that will retrieve search data from SQL and also give me directions on how to make the table name dynamic?

Any help is greatly appreciated

Mart

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T05:26:11+00:00Added an answer on May 20, 2026 at 5:26 am

    You could write a handler (.ashx) to return the query results from the db for both your text search and table names. For table names have a look at INFORMATION_SCHEMA.TABLES IN SQL Server…

    Have a look at this
    .NET AJAX Calls to ASMX or ASPX or ASHX? for a slightly more modern method using ScriptService – the basic idea is the same.

    I’ll post code tomorrow if required (its v.late),

    Hth.

    EDIT:

    At its simplest (you’ll appreciate the issues involved in doing something more involved as you go) lets imagine you have three tables: User, Department and Product.

    Table: User
    ID int
    forename varchar(50)
    surname varchar(50)
    DateOfBirth datetime

    Table: Department
    Id int
    Name varchar

    Table: Product
    Id int
    Name varchar

    And you need 3 Sprocs to select by part of the Name:

    The form of the sproc for Products and Departments is the same:

    CREATE PROCEDURE dbo.ProductSelect (dbo.DepartmentSelect)
        @qry VARCHAR(50)
    AS
    BEGIN
        SET NOCOUNT ON;
    
        SELECT *
    FROM dbo.Product  (dbo.Department)
    WHERE [Name] LIKE '%' + @qry + '%'
    END
    

    And for Users slightly different:

    CREATE PROCEDURE [dbo].[UserSelect]
        @qryTerm VARCHAR(50)
    AS
    BEGIN
    -- SET NOCOUNT ON added to prevent extra result sets from
    -- interfering with SELECT statements.
    SET NOCOUNT ON;
    
    SELECT U.Id, U.Forename + ' ' + U.Surname AS [Name], U.DateOfBirth
    FROM 
        dbo.[User] U
    WHERE
        (
            forename LIKE '%' + @qryTerm + '%'
            OR
            surname LIKE '%' + @qryTerm + '%'
        )
    ORDER BY 
        surname, Forename
    END
    

    Basic page/control markup:

    <div>
        Tables:
        <asp:DropDownList runat="server" ID="ddlTables" />
    
    </div>
    
    <div>
        <asp:TextBox runat="server" ID="txtUser" />
    </div>
    ....
    

    To bind the dropdownlist to a list of tables you need a sproc/query along the lines of:

    SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = 'dbo'
    ORDER BY TABLE_NAME
    [Change the schema name to that of your schema]

    //Bind your dropdown to the list of tables
    using (SqlConnection conn = new SqlConnection(ConfigurationManager.AppSettings["dbConnString"]))
        {
            using (SqlCommand cmnd = conn.CreateCommand())
            {
                cmnd.CommandType = CommandType.StoredProcedure;
                cmnd.CommandText = "dbo.TableSelect";
    
                conn.Open();
    
                System.Text.StringBuilder sb = new System.Text.StringBuilder();
    
                using (SqlDataReader rdr = cmnd.ExecuteReader(CommandBehavior.CloseConnection))
                {
                    string _fullName;
                    while (rdr.Read())
                    {
                        _fullName = string.Format("{0}.{1}",rdr["Table_Schema"].ToString(), rdr["Table_Name"].ToString());
                        ddlTables.Items.Add(new ListItem(_fullName,_fullName));
                    }
                    ddlTables.Items.Insert(0, new ListItem("Select Table ..."));
                }
            }
        }
    

    Then you need to wire up your textbox to a JavaScript function that responds to the keyup event:

    //Wire up the textbox
            txtUser.Attributes.Add("onkeyup", "doLookup();");
    
    function doLookup(){
    
    }
    

    The modern way of doing this is by using JQuery’s AJaX functionality. Basically you make a call to the URL of your handler which will return the query results which you then bind or output to a GUI element underneath your textbox so it looks kind of like a dropdownlist. User then clicks on one of the entries returned to copy it to the textbox.

    Some handler code:

        public void ProcessRequest(HttpContext context)
        {
            HttpRequest req = context.Request;
            if (string.IsNullOrEmpty(req.QueryString["qry"]) || string.IsNullOrEmpty(req.QueryString["tableName"])){
                return;//  You could return something meaningful if no sql query is passed
            }
    
    
            String sqlstr = req.QueryString["qry"];
            String tableName = req.QueryString["tableName"];
    
            System.Text.StringBuilder sb = new System.Text.StringBuilder();
    
            using (SqlConnection conn = new SqlConnection(ConfigurationManager.AppSettings["dbConnStr"])){
                using (SqlCommand cmnd = conn.CreateCommand())
                {
                    cmnd.CommandText = tableName + "Select";
                    cmnd.CommandType = CommandType.StoredProcedure;
                    SqlParameter pram = new SqlParameter("@qry", sqlstr);
                    pram.Direction = ParameterDirection.Input;
                    cmnd.Parameters.Add(pram);
    
                    pram = new SqlParameter("@tableName", tableName);
                    pram.Direction = ParameterDirection.Input;
                    cmnd.Parameters.Add(pram);
    
                    conn.Open();
    
                    using (SqlDataReader rdr = cmnd.ExecuteReader(CommandBehavior.CloseConnection)){
                        while (rdr.Read()){
                            sb.Append(rdr["Name"].ToString() + "<br/>"); //Modern object-oriented thing to do is build up a JSON string and return that.
                        }
                    }
    
                }
            }
    
            context.Response.ContentType = "text/plain";//or "text/JSON"
            context.Response.Write(sb.ToString());
        }
    

    Good luck. Let me know if you need any more detail…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to build a C++ extension for python using swig. I've followed the
I'm trying to write test harness for part of my Android mapping application. I
I'm trying to build a Chrome browser extension, that should enhance the way the
I am trying to redirect to a specific path based on HTTP_HOST or SERVER_NAME
I am trying to load a html page through UIWebview.I need to disable all
I am trying to understand the practical difference during the execution of a program
I am playing with TFS 2010, and am trying to setup a build process
I have several USB mass storage flash drives connected to a Ubuntu Linux computer

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.