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!