Ajax extension control AutoComplete (automatic prompt function) usage Summary

Source: Internet
Author: User

This control needs to write a WebService method for this control to call!

Page code:

<Form ID = "form1" runat = "server">
<Div>
<Asp: scriptmanager id = "scriptmanager1" runat = "server">
</ASP: scriptmanager>

<Asp: textbox id = "textbox1" runat = "server"> </ASP: textbox>
<C0: autocompleteextender id = "autocompleteextender1" runat = "server"
Targetcontrolid = "textbox1"// Control to be prompted
Servicepath = "WebService. asmx"// Path of the service to be called (in the same directory as the page)
Servicemethod = "gethostsearchbykeywords ";// Method to call the service
Minimumprefixlength = "1"// Enter at least a few words and a prompt will appear
Enablecaching = "true"// Whether to enable Cache
Completionsetcount = "2"// A few lines of prompts appear
> </PC3: autocompleteextender>
</Div>

</Form>

 

 

 

Select your website -- create WebService. asmx -- add features such

[System. Web. Script. Services. scriptservice ()]
Public class WebService: system. Web. Services. WebService
{

Public WebService ()
{

// If you use the designed component, uncomment the following line
// Initializecomponent ();
}

[Webmethod]

// This method can be changed except the name, And the rest remain unchanged.
Public String [] gethostsearchbykeywords (string prefixtext, int count)
{
Return zhanneiservice. gethostsearchbykeywords (prefixtext, count );
}

}

The method called in the above method is as follows (In the zhanneiservice class)

Public static string [] gethostsearchbykeywords (string keyseach, int count)
{
List <zhannei> li = new list <zhannei> ();
String SQL = "select top" + Count + "* From zhannei where neirong like '" + keyseach + "% 'order by neirong DESC ";
Sqldatareader DR = dbhelper. getreader (SQL );
While (dr. Read ())
{
Zhannei = new zhannei ();
Zhannei. ID = convert. toint32 (Dr ["ID"]);
Zhannei. neirong = Dr ["neirong"]. tostring ();
Zhannei. Time = convert. todatetime (Dr ["time"]);
Li. Add (zhannei );
}
List <string> result = new list <string> ();
Foreach (zhannei VaR in Li)
{
Result. Add (var. neirong );
}
Return result. toarray ();
}

Run it!

 

 

 

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.