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 8589557
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T23:05:08+00:00 2026-06-11T23:05:08+00:00

I am using AjaxControlToolkit, and binding its AutoComplete extension to a text box. With

  • 0

I am using AjaxControlToolkit, and binding its AutoComplete extension to a text box.

With the original code, I can get it to work perfectly.
My requirements have evolved from just querying and sending 1 set of data, to having to send that data with a key.

Eg:
When the user enters some text, the query searches 3 tables for a likelihood, the sends back all the results. I want to now bind these results to the table it was taken from.
The key doesn’t have to show on the extender, only the value.

My thoughts were to bind the results to a Dictionary, then loop through it to get the values (binding the values to a string[] to return to the AutoComplete), then using the Key to asign in another text box where the selected Variable came from.

Current code .aspx:

<ajaxToolkit:AutoCompleteExtender ID="AutoCompleteExtender1" runat="server" TargetControlID="txtMainSearch" ServiceMethod="GetCompletionList" CompletionInterval="500" FirstRowSelected="True" CompletionListCssClass="completionList" CompletionListItemCssClass="listItem" CompletionListHighlightedItemCssClass="itemHighlighted"></ajaxToolkit:AutoCompleteExtender>

.cs

[WebMethod, ScriptMethod]
public static string[] GetCompletionList(string prefixText)
{
    ArrayList srings = new ArrayList();

    int counter = 0;

    SqlConnection db = DataConn.SqlConnection();

    db.Open();
    SqlTransaction transaction = db.BeginTransaction();

    Dictionary<string, string> dictionary = new Dictionary<string, string>();

    try
    {
        SqlCommand command = new SqlCommand("[Table 1]" + prefixText + "[Var]", db, transaction);
        using (SqlDataReader reader = command.ExecuteReader())
        {
            while (reader.Read())
            {
                counter = counter + 1;
                dictionary.Add("ItemOne", reader["something"].ToString());
            }
        }

        command = new SqlCommand("[Table 2]", db, transaction);
        using (SqlDataReader reader = command.ExecuteReader())
        {
            while (reader.Read())
            {
                counter = counter + 1;
                dictionary.Add("ItemTwo", reader["something"].ToString());
            }
        }

        transaction.Commit();
    }
    catch (SqlException)
    {
        transaction.Rollback();
        dictionary.Add("Error", "Problem Getting Results");
    }

    if (counter == 0)
        dictionary.Add("Error", "There are no users to display");

    foreach (KeyValuePair<string, string> valuePair in dictionary)
    {
        srings.Add(valuePair.Value);
    }

    return null; //This isnt really null... Just accidently deleted the code
}
  • 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-06-11T23:05:09+00:00Added an answer on June 11, 2026 at 11:05 pm

    the main problem is that you attempting to add duplicate keys into dictionary. Use List<KeyValuePair<string, string>> collection instead:

    var values = new List<KeyValuePair<string, string>>();
    
    // select data from first table
    foreach (var id in Enumerable.Range(1,10))
    {
        values.Add(new KeyValuePair<string,string>("Table1_" + id.ToString(), Guid.NewGuid().ToString() );
    }
    
    //select data from the second table
    foreach (var id in Enumerable.Range(1,10))
    {
        values.Add(new KeyValuePair<string,string>("Table2_" + id.ToString(), Guid.NewGuid().ToString() );
    }
    
    if(values.Count == 0)
    {
        values.Add(new KeyValuePair<string,string>("", "There are no users to display"));
    }
    
    return values.Select( pair => AutoCompleteExtender.CreateAutoCompleteItem(pair.Value, pair.Key)).ToArray();
    

    Draw attention that item’s key generated from source table name and key value itself.

    Then, on page add to AutoCompleteExtender OnClientItemSelected client event handler and add hidden field on form to store selected item value:

    <script type="text/javascript">
         function itemSelected(sender, args) {
              $get("<%= AutoCompleteSelectedValue.ClientID %>").value = args.get_value();
         }
    </script>
    
    <ajaxToolkit:AutoCompleteExtender ID="AutoCompleteExtender1" runat="server" TargetControlID="txtMainSearch"
         ServiceMethod="GetCompletionList" CompletionInterval="500" FirstRowSelected="True"
         CompletionListCssClass="completionList" CompletionListItemCssClass="listItem"
         CompletionListHighlightedItemCssClass="itemHighlighted"
         OnClientItemSelected="itemSelected">
    
    <asp:HiddenField runat="server" ID="AutoCompleteSelectedValue" />
    

    After that you may get selected value from AutoCompleteSelectedValue hidden field and parse it.

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

Sidebar

Related Questions

Using Location.getBearing(); I seem to get randomly changing bearings. Aka, I can turn the
I am using AjaxControlToolkit CalendarExtender. Some previous rule in my stylesheet is affecting div's
In have my application configured in asp.net. I am using ajaxcontroltoolkit. After building the
I am using the HtmlEditor Control included in the AjaxControlToolkit (patched version v62210 because
using this http://bl.ocks.org/950642 we can see how to add images to nodes, the question
Using the Redis info command, I am able to get all the stats of
Please help me to get text (non html/ not formatted) from ajax text editor
I am using MonoDevelop on MacOS and I am having difficulty getting AjaxControlToolkit's TabContainer
I have added AjaxControlToolKit.dll to my web project and using couple of controls on
Is it possible to populate the AjaxControlToolkit ComboBox with jQuery using a webservice. I

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.