ASP. NET Ajax Control Toolkit implement fuzzy search by pinyin drop-down box

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.