前台代码:<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" > <head id="Head1" runat="server"> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> </head> <body> <Form id="form1" runat="server"> <asp:ScriptManager ID="sm" runat="server"> </asp:ScriptManager> <asp:TextBox ID="TextBox1" runat="server" CssClass="unwatermarked"></asp:TextBox> <ajaxToolkit:AutoCompleteExtender ID="AutoCompleteExtender1" runat="server" TargetControlID="TextBox1" MinimumPrefixLength="1" EnableCaching="true" CompletionSetCount="7" CompletionInterval="1000" ServiceMethod="GetCPKeyWord" ServicePath="webservice/GetKeyWords.asmx" CompletionListCssClass="autocomplete_completionListElement" CompletionListItemCssClass="autocomplete_listItem" CompletionListHighlightedItemCssClass="autocomplete_highlightedListItem" DelimiterCharacters=";, :" FirstRowSelected="True" > <Animations> <OnShow> <Sequence> <OpacityAction Opacity="0" /> <HideAction Visible="true" /> <Parallel Duration=".2"> <FadeIn /> </Parallel> </Sequence> </OnShow> <OnHide> <Parallel Duration=".4"> <FadeOut /> </Parallel> </OnHide> </Animations> </ajaxToolkit:AutoCompleteExtender> </Form> </body> </html> webservice方法: using System; using System.Web; using System.Collections; using System.Web.Services; using System.Web.Services.Protocols; using System.Collections.Generic; using System.Data; using System.Web.Caching; using BLL; /// <summary> /// GetKeyWords 的摘要说明 /// </summary> [WebService(Namespace = "http://tempuri.org/")] [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] [System.Web.Script.Services.ScriptService] public class GetKeyWords : System.Web.Services.WebService { public GetKeyWords() { //如果使用设计的组件,请取消注释以下行 //InitializeComponent(); } /// <summary> /// 查找产品关键字 /// </summary> /// <param name="prefixText"></param> /// <param name="count"></param> /// <returns></returns> [WebMethod] public string[] GetCPKeyWord(string prefixText, int count) { List<string> _keyList = new List<string>(); DataTable _myTable; cptjkeyword _myOper = new cptjkeyword(); _myTable = _myOper.GetKeyWord(prefixText, count); foreach (DataRow _r in _myTable.Rows) { _keyList.Add(_r[1].ToString()); } return _keyList.ToArray(); } /// <summary> /// 查找零售商关键字 /// </summary> /// <param name="prefixText"></param> /// <param name="count"></param> /// <returns></returns> [WebMethod] public string[] GetLssKeyWords(string prefixText, int count) { List<string> _keyList = new List<string>(); DataTable _myTable; LssKeyWords _myOper = new LssKeyWords(); _myTable = _myOper.SelectTopLssKeyWords(prefixText, count); foreach (DataRow _r in _myTable.Rows) { _keyList.Add(_r[1].ToString()); } return _keyList.ToArray(); } }