[WebService(Namespace = "http://tempuri.org/")] [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] [System.Web.Script.Services.ScriptService] // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. // [System.Web.Script.Services.ScriptService] public class AutoCompleteService : System.Web.Services.WebService { }
ServicePath="~/Service/MyAutoCompleteService.asmx"
Regards, Raja, USA
<body> <form id="form1" runat="server"> <asp:ScriptManager ID="ScriptManager1" runat="server"> </asp:ScriptManager> <div> <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> <cc1:AutoCompleteExtender ID="TextBox1_AutoCompleteExtender" runat="server" DelimiterCharacters="" Enabled="True" ServiceMethod="GetCompletionList" ServicePath="" TargetControlID="TextBox1" UseContextKey="True" MinimumPrefixLength="1"> </cc1:AutoCompleteExtender> </div> </form> </body>
[System.Web.Services.WebMethodAttribute(), System.Web.Script.Services.ScriptMethodAttribute()] public static string[] GetCompletionList(string prefixText, int count, string contextKey) { string conn = ConfigurationManager.ConnectionStrings["employeeConnectionString"].ConnectionString; SqlConnection con = new SqlConnection(conn); DataSet ds = new DataSet(); SqlDataAdapter da = new SqlDataAdapter("SELECT [empname] FROM [employee]", con); da.Fill(ds,"employee"); string[] main = new string[0]; for (int i = 0; i < ds.Tables[0].Rows.Count-1; i++) { if (ds.Tables[0].Rows[i].ItemArray[0].ToString().ToLower().StartsWith(prefixText.ToLower())) { Array.Resize(ref main, main.Length + 1); main[main.Length - 1] = ds.Tables[0].Rows[i].ItemArray[0].ToString (); if (main.Length == 10) break; } } Array.Sort(main); return main; }
https://wordpress.com/pages/anuphosur.wordpress.com
Login to post response