JS Script Reference
Copy codeThe Code is as follows:
<Script src = "/scripts/Jquery. autocomplete/jquery. autocomplete. js" type = "text/javascript"> </script>
Style reference
Copy codeThe Code is as follows:
<Style type = "text/css" media = "all">
@ Import url ("/scripts/Jquery. autocomplete/css/jquery.autocomplete.css ");
</Style>
JS Code
Copy codeThe Code is as follows:
? $ (Document). ready (function (){
$ ("# <% = _ SearchKeyGame. ClientID %>"). autocomplete ("./AjaxHandle/AutoComplete. ashx? Type = game ",{
MinChars: 0,
Max: 9,
Width: 150,
MatchContains: true,
AutoFill: false,
FormatItem: function (row, I, max ){
Return row. name;
},
FormatMatch: function (row, I, max ){
Return row. name + "";
},
FormatResult: function (row ){
Return row. name;
}
});
JQuery ("# <% = _ SearchKeyGame. ClientID %>"). result (function (event, data, formatted ){
If (data ){
JQuery ("# _ SearchKeyGame"). attr ("value", data. name );
}
Else {
}
});
$ ("# <% = _ SearchKeyPlat. ClientID %>"). autocomplete ("./AjaxHandle/AutoComplete. ashx? Type = plat ",{
MinChars: 0,
Max: 9,
Width: 150,
MatchContains: true,
AutoFill: false,
FormatItem: function (row, I, max ){
Return row. name;
},
FormatMatch: function (row, I, max ){
Return row. name + "";
},
FormatResult: function (row ){
Return row. name;
}
});
AutoComplete. Ashx returns the JOSON value.
Copy codeThe Code is as follows:
String queryStr = context. Request. QueryString ["q"];
Context. Response. ContentType = "text/plain ";
Context. Response. Cache. SetNoStore ();
String July string = "[";
String where = string. format ("(select dbo. [f_GetPy] (platname) like '% {0} %' or platname like '% {0} %' ", Common. common. toSql (queryStr ));
DataTable dt = new Models. Plat (). GetDataTable (where, 10 );
If (dt. Rows. Count> 0)
{
For (int I = 0; I <dt. Rows. Count; I ++)
{
July string + = "{id: \" "+ dt. rows [I] ["PlatID"]. toString () + "\", name: \ "" + dt. rows [I] ["PlatName"]. toString () + "\"},";
}
}
JsponString = jsponString. Trim (new char [] {','});
July string + = "]";
Context. Response. Write (j1_string );
Context. Response. End ();