1.前台代码:??
js:
?<style type="text/css">
?
? .backgroudcolor
? {
? ?background-color:#D6FAF9;
? }
? .onmouservoer
? {
? ? background-color:#E9EDAF;
? }
? </style>
??
?
<div>
??????? <asp:ScriptManager ID="ScriptManager1" runat="server">
??????? </asp:ScriptManager>
???
???
??????? <asp:TextBox ID="TextBox1" runat="server" AutoPostBack="True"
??????????? ontextchanged="TextBox1_TextChanged"></asp:TextBox>
??????? <cc1:AutoCompleteExtender ID="AutoCompleteExtender1" runat="server" TargetControlID="TextBox1"
???????? ServicePath="testwebservers.asmx" ServiceMethod="GetHotSearchBywords" MinimumPrefixLength="1" CompletionInterval="500"
????????? EnableCaching="true" CompletionSetCount="10"? CompletionListItemCssClass="backgroudcolor"? CompletionListHighlightedItemCssClass="onmouservoer">
??????? </cc1:AutoCompleteExtender>
??????? </div>
2.后台代码:
webserver:
? [WebService(Namespace = "http://tempuri.org/")]
??? [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
??? [ToolboxItem(false)]
??? // 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 testwebservers : System.Web.Services.WebService
??? {
??????? [WebMethod]
??????? public string[] GetHotSearchBywords(string prefixText,int count)
??????? {
??????????? return BookManager.GetBookKeywords(prefixText,count);
??????? }
??? }
?
bll 省略...
dal:
?public static string[] GetBookKeywords(string keyword,int displaycount)
????? {
????????? IList<Book> book = new List<Book>();
????????? List<string> result = new List<string>(displaycount);
????????? string sql = "select top 10 * from Book where title like '%" + keyword + "%' order by id";
????????? book =getALLBookBySql(sql);
????????? foreach (Book item in book)
????????? {
????????????? result.Add(item.Title);
????????? }????????? return result.ToArray();????? }