Solved

Multi column or ItemData in AJAX AutoCompleteExtender?

Posted on 2009-03-31
6
3,333 Views
Last Modified: 2013-11-07
I've got the AJAX AutoCompleteExtender working in my project. For example, one of them a list of suburbs - if you type in "BUR" it will start listing "BURWOOD" "BURWOOD EAST" etc.

That's great, except that to really use the response, I need to access an ID number, not the string itself. For example, the submitted page needs to use Suburb_ID 1500 rather than the string "BURWOOD".

The lazy approach would be to run SQL queries to translate the string back into the ID ("SELECT ID FROM Suburbs WHERE Name = 'BURWOOD'; ") but architecturally and performance wise this is dreadful.

So my question: Is there a way to for AJAX AutoCompleteExtender to store multiple columns, or, associated item data with each item it lists?
0
Comment
Question by:blowfly
6 Comments
 
LVL 96

Accepted Solution

by:
Bob Learned earned 500 total points
ID: 24048428
I would have to say that I don't remember the AutoCompleteExtender providing that kind of support.
0
 

Author Comment

by:blowfly
ID: 24083931
Fair enough, any ideas on a free/open source alternative which might do this?

Otherwise points to you.
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 24086287
No, but if you find one, it would be a "treasure"...

I am not saying that one doesn't exist, and that the AutoCompleteExtender doesn't support it.  I am saying that I don't know of any solution...
0
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 

Author Closing Comment

by:blowfly
ID: 31565152
Fair enough, thanks for the help.
0
 

Expert Comment

by:avm7878
ID: 24265939
You can accomplish it one of 2 ways. You can create a Custom Control that inherits the AutoCompleteExtender class and override the Render event.

Or... you can go with this guy's javascript solution:
http://www.darwyn.com/blogs/post/2009/03/03/custom-Auto-Complete-Extender-Extended.aspx
0
 

Expert Comment

by:AyhanEren75
ID: 24525232
If I did not misunderstand the need, here is you can try a couple of lines.
 using (SqlConnection ConnStr = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["connectionString"].ConnectionString))
            {
                ConnStr.Open();
                SqlCommand sqlcmd = new SqlCommand(@"NameOfTheStoredProcedure", ConnStr);
                
	  sqlcmd.CommandType = CommandType.StoredProcedure;                
                sqlcmd.Parameters.Add("@ourComingEnteredWord", SqlDbType.NVarChar, 50).Value = prefixText.Trim().ToLower();
                
                SqlDataAdapter da = new SqlDataAdapter(sqlcmd);
                DataTable dt = new DataTable("ResultTable");
 
                try
                {
                    da.Fill(dt);
                }
                catch {
                
                }
 
                string[] items = new string[dt.Rows.Count];
                int i = 0;
 
                foreach (DataRow dr in dt.Rows)
                {
                    //added for keyvalue pair feature.
                    items.SetValue(AjaxControlToolkit.AutoCompleteExtender.CreateAutoCompleteItem(dr["SuburbName"].ToString(), dr["SuburbID"].ToString()), i);
                    
                    i++;
                }
 
                
                return items;
 
            }//end of sqlconnection   

Open in new window

0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

770 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