1. the Ajax implementation method is as follows:
Webpage:
<asp:ScriptManager ID="ScriptManager1" runat="server"/><cc1:AutoCompleteExtender ID="AutoCompleteExtender1" runat="server" ServiceMethod="CusName" ServicePath="AutoService.asmx"TargetControlID="customer" MinimumPrefixLength="1" EnableCaching="true" ></cc1:AutoCompleteExtender>
Webserver:
[Webmethod] Public String [] cusname (string prefixtext) {webclass. list TMP = new webclass. list (); dbdatareader DR = TMP. showname (prefixtext); List <string> suggestions = new list <string> (); // declare a generic set while (dr. read () {suggestions. add (dr. getstring (0);} Dr. close (); Return suggestions. toarray ();}
2. The jquer implementation method is as follows:
Project to be introduced:
<link href="css/jquery.autocomplete.css" rel="stylesheet" type="text/css" /> <script language="JavaScript" type="text/javascript" src="js/jquery.js"></script> <script language="JavaScript" type="text/javascript" src="js/jquery.autocomplete.js"></script>
jvascript:
$(document).ready(function(){ $("#contactperson").autocomplete("AutoHandler.ashx",{ delay:10, minChars:2, matchSubset:1, cacheLength:1, onItemSelect:selectItem, onFindValue:findValue, autoFill:true, maxItemsToShow:20 }); });
Ashx:
Public void processrequest (httpcontext context) {// context. response. contenttype = "text/plain"; // context. response. write ("Hello World"); string prefixtext = context. request. querystring ["Q"]; webclass. rfslist TMP = new webclass. rfslist (); dbdatareader DR = TMP. showcusname (prefixtext); stringbuilder items = new stringbuilder (); While (dr. read () {items. append (dr. getstring (0) + "\ n");} Dr. close (); context. response. write (items. tostring (); context. response. end ();}
Similar to the aspx webpage, CSS is as follows:
.ac_results {padding: 0px;border: 1px solid WindowFrame;background-color: Window;overflow: hidden;}.ac_results ul {width: 100%;list-style-position: outside;list-style: none;padding: 0;margin: 0;}.ac_results iframe {display:none;/*sorry for IE5*/display/**/:block;/*sorry for IE5*/position:absolute;top:0;left:0;z-index:-1;filter:mask();width:3000px;height:3000px;}.ac_results li {margin: 0px;padding: 2px 5px;cursor: pointer;display: block;width: 100%;font: menu;font-size: 12px;overflow: hidden;}.ac_loading {background : Window url('../img/onload.gif') right center no-repeat;}.ac_over {background-color: Highlight;color: HighlightText;}
Jquery and jquery AutoComplete will not be pasted.
/Files/cnaspnet/jqueryautocomplete.rar