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 a stock.CodeFor example, enter a part of the Code, an abbreviation of Pinyin, or a Chinese character 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>
///Stockcode Summary
/// </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 components, uncomment the following lines:
//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","Bananas","Sausage"} ;
}
:
Sample Code:
/Files/heekui/stockid.rar
Running environment:
Vs2005 and ASP. NET Ajax v 1.0 + ASP. NET Ajax Control Toolkit