Solved

jQuery Autocomplete : Is there a way to add two column in the droplist

Posted on 2009-05-05
1
2,160 Views
Last Modified: 2012-05-06
Hi, I am building a web application that requires to search part numbers.

I have set up the Autocomplete plugins from jQuery using a Generic Hanlder and it works fine.

I was wondering though if it is possible to have two columns in the droplist.

I search by Item Code and I'd like to have | ItemCode    | Description |  to show up in the droplist.

Thanks,
// Javascript
 
<script type="text/javascript">
 
$(document).ready(function(){
  $("#ctl00_ContentPlaceHolder1_txtSearchPart").autocomplete(
    "ctrl/AutocompleteData.ashx",
        {
            width: 500,
            scrollHeight: 230
        }
    );
  });
 
</script>
 
 
// Generic Hanlder
 
<%@ WebHandler Language="C#" Class="AutocompleteData" %>
 
using System;
using System.Web;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
 
public class AutocompleteData : IHttpHandler {
    
    public void ProcessRequest (HttpContext context) {
        string srValue = context.Request.QueryString["q"];
        string sql = "SELECT TOP 20 ItemCode FROM Items WHERE ItemCode like '" + srValue + "%'";
 
        using (SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["cn"].ConnectionString))
        using (SqlCommand cmd = new SqlCommand("sel_ajaxPartsCompletor", connection))
        {
            cmd.CommandType = CommandType.StoredProcedure;
            SqlParameter value = new SqlParameter("strValue", SqlDbType.VarChar);
            value.Value = srValue.ToString();
            cmd.Parameters.Add(value);
            connection.Open();
 
            using (SqlDataReader reader = cmd.ExecuteReader())
            {
                while (reader.Read())
                {
                    context.Response.Write(reader.GetString(0) + Environment.NewLine);
                }
            }
        }
    }
 
    public bool IsReusable {
        get {
            return false;
        }
    }
 
}

Open in new window

0
Comment
Question by:maxleb
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 13

Accepted Solution

by:
dungla earned 500 total points
ID: 24341310
Hi there,
http://www.codeproject.com/KB/ajax/jqueryajax.aspx this may help you out with Multi-column auto-complete
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Chart.js, used properly, can visually add a difference to your charting applications. It engages your visitors and allows them to interact with data they otherwise wouldn't be able to without expensive and complicated systems. For this…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

696 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question