Last post Jan 29, 2015 02:28 AM by Zhi Lv - MSFT
Jan 27, 2015 09:43 AM|DaWanderer|LINK
I am using AJAX AutoCompleteExtender on a TextBox and have a problem in regard to passing the Completion List value(from the Auto complete list generated by the AutoCompleteExtender) to the TextBox.
Let me explain how my Web Form is organized.
I have got a text box that searches people in an organisation. Auto complete provides suggestions as the user starts typing the text. As people can have the same name, the list displayed includes their department as well to help the user find the exact person.
Now, when the user selects an item, I want the value that is passed to the text box to be
only the name of the person because clicking on search button queries the database where name='text in the textbox'. If department is also passed, the search query fails.
Or another thing that I could do with is : when the user selects an item, can i fire a query and skip the press of the search button all together?
Please point me to any related link or source.
Jan 27, 2015 10:28 AM|jiveabillion|LINK
Since you are not using a dropdown list, a simple way to do this would be to put a separator that would not be in someone's name in your text like: John Smith -> Accounting
You can then strip out the department name before passing the value to the query:
string valueForQuery = textboxValue.SubString(0,textboxValue.LastIndexOf("->")).Trim();
Jan 27, 2015 12:20 PM|DaWanderer|LINK
This is one solution which I thought of as well but I'm looking for something more elegant.
Also, Is there any way I can return something other than the List<string>?
Maybe if I can return a listView with multiple columns, I could do something and pass just 1st column for each row which contains only name of the person.
Or maybe I can use the AutoCompleteExtender on a Dropdown and force the user to select a value from the list only?
Jan 27, 2015 02:58 PM|jiveabillion|LINK
I'm not sure if you can do it easily with the AutoCompleteExtender, but you may be able to do it with Kendo UI's autocomplete
Sometimes though, the best solution at the time isn't so elegant.
Jan 29, 2015 02:28 AM|Zhi Lv - MSFT|LINK
Welcome to ASP.NET forum.
From my point of view, I suppose you could try to add a DropDownList control and bind the department. Then, when your query the database, you could use the department and
user name as parameters. Like this.
<%-- Dropdownlist for Department --%>
<asp:DropDownList ID="DropDownList1" runat="server"></asp:DropDownList><br />
<%-- User Name with autocomplete--%>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox><br />