Autocomplete prompt from database for textbox using ajax autocomplete extender
public string[] GetLocationInfo(string prefixText) { int count = 10; string sql = "Select * from Locations Where Location like @prefixText"; SqlDataAdapter da = new SqlDataAdapter(sql,webindia.Connstring); da.SelectCommand.Parameters.Add("@prefixText", SqlDbType.VarChar, 50).Value = prefixText+ "%"; DataTable dt = new DataTable(); da.Fill(dt); string[] items = new string[dt.Rows.Count]; int i = 0; foreach (DataRow dr in dt.Rows) { items.SetValue(dr["Location"].ToString(),i); i++; } return items; }
<asp:TextBox Maxlength="50" id="txtname2" class="bdtxt" onblur="this.value=Trim(this.value)" onkeypress="return noNumbers(event)" runat="server"/>
<cc1:AutoCompleteExtender CompletionListCssClass="Completer_completionListElement FS-NBK" CompletionListItemCssClass="Completer_listItem" CompletionListHighlightedItemCssClass="Completer_highlightedListItem" ID="AutoCompleteExtender1" runat="server" MinimumPrefixLength="1" ShowOnlyCurrentWordInCompletionListItem="true" ServiceMethod="GetLocationInfo" FirstRowSelected="true" ServicePath="WebService.asmx" TargetControlID="txtname2"> </cc1:AutoCompleteExtender>