AjaxControlToolkit AutoComplete with Dictionary

FofFlounk

New Member
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: \[code\]<ajaxToolkit:AutoCompleteExtender ID="AutoCompleteExtender1" runat="server" TargetControlID="txtMainSearch" ServiceMethod="GetCompletionList" CompletionInterval="500" FirstRowSelected="True" CompletionListCssClass="completionList" CompletionListItemCssClass="listItem" CompletionListHighlightedItemCssClass="itemHighlighted"></ajaxToolkit:AutoCompleteExtender>\[/code\].cs\[code\][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}\[/code\]
 
Back
Top