Foreground HTML:
<HTML xmlns = "http://www.w3.org/1999/xhtml">
<Head runat = "server">
<Title> </title>
<SCRIPT src = "jquery-1.3.2-vsdoc2.js" type = "text/JavaScript"> </SCRIPT>
<SCRIPT src = "jquery/AutoComplete/jquery. autocomplete. Min. js" type = "text/JavaScript"> </SCRIPT>
<Link href = "jquery/AutoComplete/jquery.autocomplete.css" rel = "stylesheet" type = "text/CSS"/>
<SCRIPT type = "text/JavaScript">
$ (). Ready (function (){
$ ("# T_person"). Focus (). AutoComplete ("ajax_do.aspx? Page = texttishi & dotype = 1 ",{
MAX: 1000,
Width: 150,
Selectfirst: false
});
});
</SCRIPT>
</Head>
<Body>
<Form ID = "form1" runat = "server">
<Div>
<Input type = "text" id = "t_person"/>
</Div>
</Form>
</Body>
</Html>
Background (ajax_do.aspx.cs ):
Using (sqlconnection con = new sqlconnection (gclass. connmybo ))
{
String strret = "";
String key = request. Params ["Q"]. tostring ();
String sort sel = "select party_id from person where party_id like @ key ";
Sqlcommand cmd = new sqlcommand (SEL Sel, con );
Con. open ();
Cmd. Parameters. addwithvalue ("key", "%" + key + "% ");
Sqldatareader reader = cmd. executereader ();
While (reader. Read ())
{
Strret + = reader [0]. tostring () + "\ n ";
}
Response. Write (strret );
}
Note:
The default AutoComplete keyword is Q. You can use request. Params ["Q"] in the background to obtain the value of the currently entered text box.