We have always hoped that Atlas will provide AutoComplete extension features, and we will be able to live up to expectations. This feature is already included in the latest ASP. NET Ajax Control Toolkit: autocompleteextender. It is easy to use.
The following is an example of stock code query. You can enter some code, Pinyin abbreviations, or Chinese characters to get all the prompts.
1. Add a textbox.
<Asp: textbox runat = "server" id = "txtstockkeyname" width = "300" AutoComplete = "off"/>
2. Add autocompleteextender and set parameters.
<PC3: autocompleteextender
Runat = "server"
Id = "autocomplete1"
Targetcontrolid = "txtstockkeyname"
Servicepath = "stockcode. asmx"
Servicemethod = "getstocklist"
Minimumprefixlength = "1"
Completioninterval = "1000"
Enablecaching = "true"
Completionsetcount = "12"
/>
Parameter description:
Targetcontrolid: Enter the text box for the query keyword
Servicepath: the address of the backend WebService
Servicemethod: Method Name of the WebService corresponding to the background
Minimumprefixlength: the minimum length automatically completed when a keyword is queried.
Completioninterval: Query Result Display interval (MS)
Enablecaching: Enable Cache
Completionsetcount: displays the number of query results
3. WebService Method for returning query results based on query keywords
Using system;
Using system. Web;
Using system. collections;
Using system. Web. Services;
Using system. Web. Services. Protocols;
Using system. Collections. Generic;
Using system. collections;
/** // <Summary>
/// Summary of stockcode
/// </Summary>
[WebService (namespace = "http://tempuri.org/")]
[Webservicebinding (conformsto = wsiprofiles. basicprofile1_1)]
[System. Web. Script. Services. scriptservice]
Public class stockcode: system. Web. Services. WebService {
Public stockcode (){
// If you use the designed component, uncomment the following line
// Initializecomponent ();
}
[Webmethod]
Public String [] getstocklist (string prefixtext, int count)
{
If (COUNT = 0)
{
Count = 10;
}
Random random = new random ();
List <string> items = new list <string> (count );
For (INT I = 0; I <stockid. length; I ++)
{
If (
(Stockid [I]. indexof (prefixtext)> = 0)
| (Stockname [I]. indexof (prefixtext)> = 0)
| (Stockpy [I]. toupper (). indexof (prefixtext. toupper ()> = 0)
)
{
Items. Add (stockid [I] + ":" + stockname [I]);
}
}
Return items. toarray ();
}
// Stock code
String [] stockid = {"610001", "610002", "611003", "611004 "};
// Abbreviation of stock pinyin
String [] stockpy = {"XG", "NG", "XJ", "XC "};
// Stock name
String [] stockname = {"watermelon", "Pumpkin", "banana", "sausage "};
}
:
Sample Code:
/Files/heekui/stockid.rar
Running environment:
Vs2005 and ASP. NET Ajax v 1.0 + ASP. NET Ajax Control Toolkit