<asp:TextBox ID="txtAutoComplete" runat="server"></asp:TextBox> <ajax:AutoCompleteExtender ID="AutoCompleteExtender1" runat="server" TargetControlID="txtAutoComplete" MinimumPrefixLength="1" EnableCaching="true" CompletionInterval="100" ServiceMethod="GetSuggessions" UseContextKey="true" ContextKey="<%# Eval(ddlState.SelectedValue) %>" CompletionSetCount="20" > </ajax:AutoCompleteExtender>
[System.Web.Script.Services.ScriptMethod()] [System.Web.Services.WebMethod] public static List<string> GetSuggessions(string prefixText, int count, long contextKey) { // prefixText – text entered in the textbox //fill list with suggestive words that will be populated in the list below the textbox // List<string> res = new List<string>() { "a", "a1", "a2", "a3", "b", "b1", "b2", "b3" }; List<string> res = MasterDTO.GetCities(contextKey).Select(s => s.CityName.ToLower()).ToList(); List<string> suggestions = res .Where(a => a.StartsWith(prefixText.ToLower())) .Take(count) .ToList(); // contextKey can be used to set further filter return suggestions; }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)