[WebService(Namespace = "http://tempuri.org/")] [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] [System.Web.Script.Services.ScriptService()] [System.ComponentModel.ToolboxItem(false)] public class WebService1 : System.Web.Services.WebService { [WebMethod] public string[] GetCities(string prefixText) { SqlConnection con = new SqlConnection(@"Data Source=(LocalDB)\v11.0;AttachDbFilename=C:Database.mdf;Integrated Security=True;MultipleActiveResultSets=True;Connect Timeout=30;Application Name=EntityFramework"); con.Open(); string strQuery = "select Source from Reservation where Source like '" + prefixText + "%'"; DataSet ds = new DataSet(); SqlDataAdapter da = new SqlDataAdapter(strQuery, con); da.Fill(ds); con.Close(); List<string> cityList = new List<string>(); for (int i = 0; i < ds.Tables[0].Rows.Count; i++) { cityList.Add(ds.Tables[0].Rows[i][0].ToString()); } con.Close(); return cityList.ToArray(); } }
<%@ Register TagPrefix="ac" Namespace="AjaxControlToolkit" Assembly="AjaxControlToolkit" %>
<asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods = "true" ></asp:ScriptManager> <asp:TextBox ID="txtCity" runat="server" AutoCompleteType="Disabled"></asp:TextBox> <ac:AutoCompleteExtender ID="AutoCompleteExtender1" BehaviorID="AutoCompleteCities" TargetControlID="txtCity" ServiceMethod="GetCities" ServicePath="WebService1.asmx" MinimumPrefixLength="1" CompletionSetCount="10" CompletionInterval="100" EnableCaching="false" runat="server" FirstRowSelected = "false" > </ac:AutoCompleteExtender>
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)