C# · 12月 20, 2021

C#—ASP页面的下拉框模糊查询功能

 

<div class=”cnblogs_code”>

= == (DaTarow daTarow dictionary = Dictionary (DataColumn dataColumn

二. 加入一般处理程序,将上一步的Json字符串写入HTTP响应输出流,传到前端页面

 

<span style=”color: #0000ff;”>using<span style=”color: #000000;”> System;
<span style=”color: #0000ff;”>using<span style=”color: #000000;”> System.Web;
<span style=”color: #0000ff;”>using<span style=”color: #000000;”> SysManage;
<span style=”color: #0000ff;”>using<span style=”color: #000000;”> System.Data;
<span style=”color: #0000ff;”>public <span style=”color: #0000ff;”>class<span style=”color: #000000;”> Xcode : IHttpHandler
{
<span style=”color: #0000ff;”>public <span style=”color: #0000ff;”>void<span style=”color: #000000;”> ProcessRequest(HttpContext context)
{
context.Response.ContentType = <span style=”color: #800000;”>”<span style=”color: #800000;”>application/json<span style=”color: #800000;”>”<span style=”color: #000000;”>;
<span style=”color: #0000ff;”>string str = context.Request[<span style=”color: #800000;”>”<span style=”color: #800000;”>type<span style=”color: #800000;”>”<span style=”color: #000000;”>];
<span style=”color: #0000ff;”>string sql = <span style=”color: #0000ff;”>string.Format(<span style=”color: #800000;”>”<span style=”color: #800000;”>select * from XCode where XCODE like ‘{0}%'<span style=”color: #800000;”>”<span style=”color: #000000;”>,str);
Database dt = <span style=”color: #0000ff;”>new<span style=”color: #000000;”> Database();
DataTable data =<span style=”color: #000000;”> dt.Executesql(sql);

context.Response.Write(Data2Json.convertJson(data));}</span><span style=”color: #0000ff;”&gt;public</span> <span style=”color: #0000ff;”&gt;bool</span><span style=”color: #000000;”&gt; IsReusable{ </span><span style=”color: #0000ff;”&gt;get</span> { <span style=”color: #0000ff;”&gt;return</span> <span style=”color: #0000ff;”&gt;false</span><span style=”color: #000000;”&gt;; }}

}

<span style=”background-color: #f5f5f5; color: #0000ff;”&gt;function</span><span style=”background-color: #f5f5f5; color: #000000;”&gt; dataFind() { </span><span style=”background-color: #f5f5f5; color: #0000ff;”&gt;var</span><span style=”background-color: #f5f5f5; color: #000000;”&gt; fl </span><span style=”background-color: #f5f5f5; color: #000000;”&gt;=</span><span style=”background-color: #f5f5f5; color: #000000;”&gt; $(</span><span style=”background-color: #f5f5f5; color: #000000;”&gt;”</span><span style=”background-color: #f5f5f5; color: #000000;”&gt;input[name=’Rblflcode’]:checked</span><span style=”background-color: #f5f5f5; color: #000000;”&gt;”</span><span style=”background-color: #f5f5f5; color: #000000;”&gt;).val(); $.ajax({ contentType: </span><span style=”background-color: #f5f5f5; color: #000000;”&gt;”</span><span style=”background-color: #f5f5f5; color: #000000;”&gt;application/json</span><span style=”background-color: #f5f5f5; color: #000000;”&gt;”</span><span style=”background-color: #f5f5f5; color: #000000;”&gt;,url: </span><span style=”background-color: #f5f5f5; color: #000000;”&gt;”</span><span style=”background-color: #f5f5f5; color: #000000;”&gt;../Xcode.ashx?type=</span><span style=”background-color: #f5f5f5; color: #000000;”&gt;”</span> <span style=”background-color: #f5f5f5; color: #000000;”&gt;+</span><span style=”background-color: #f5f5f5; color: #000000;”&gt; fl,dataType: </span><span style=”background-color: #f5f5f5; color: #000000;”&gt;”</span><span style=”background-color: #f5f5f5; color: #000000;”&gt;json</span><span style=”background-color: #f5f5f5; color: #000000;”&gt;”</span><span style=”background-color: #f5f5f5; color: #000000;”&gt;,success: </span><span style=”background-color: #f5f5f5; color: #0000ff;”&gt;function</span><span style=”background-color: #f5f5f5; color: #000000;”&gt; (msg) { </span><span style=”background-color: #f5f5f5; color: #0000ff;”&gt;if</span><span style=”background-color: #f5f5f5; color: #000000;”&gt; (msg </span><span style=”background-color: #f5f5f5; color: #000000;”&gt;==</span> <span style=”background-color: #f5f5f5; color: #0000ff;”&gt;null</span><span style=”background-color: #f5f5f5; color: #000000;”&gt;) { } </span><span style=”background-color: #f5f5f5; color: #0000ff;”&gt;else</span> <span style=”background-color: #f5f5f5; color: #0000ff;”&gt;if</span><span style=”background-color: #f5f5f5; color: #000000;”&gt; (msg </span><span style=”background-color: #f5f5f5; color: #000000;”&gt;!=</span> <span style=”background-color: #f5f5f5; color: #0000ff;”&gt;null</span><span style=”background-color: #f5f5f5; color: #000000;”&gt;) { jQuery(</span><span style=”background-color: #f5f5f5; color: #0000ff;”&gt;function</span><span style=”background-color: #f5f5f5; color: #000000;”&gt; ($) { $(</span><span style=”background-color: #f5f5f5; color: #000000;”&gt;”</span><span style=”background-color: #f5f5f5; color: #000000;”&gt;#flxzTb</span><span style=”background-color: #f5f5f5; color: #000000;”&gt;”</span><span style=”background-color: #f5f5f5; color: #000000;”&gt;).autocomplete(msg,{ minChars: </span><span style=”background-color: #f5f5f5; color: #000000;”&gt;0</span><span style=”background-color: #f5f5f5; color: #000000;”&gt;,autoFill: </span><span style=”background-color: #f5f5f5; color: #0000ff;”&gt;false</span><span style=”background-color: #f5f5f5; color: #000000;”&gt;,</span><span style=”background-color: #f5f5f5; color: #008000;”&gt;//</span><span style=”background-color: #f5f5f5; color: #008000;”&gt;是否选多个,用”,”分开</span>

<span style=”background-color: #f5f5f5; color: #000000;”> mustMatch: <span style=”background-color: #f5f5f5; color: #0000ff;”>false<span style=”background-color: #f5f5f5; color: #000000;”>,<span style=”background-color: #f5f5f5; color: #008000;”>//<span style=”background-color: #f5f5f5; color: #008000;”>是否全匹配,如数据中没有此数据,将无法输入
<span style=”background-color: #f5f5f5; color: #000000;”> matchContains: <span style=”background-color: #f5f5f5; color: #0000ff;”>true<span style=”background-color: #f5f5f5; color: #000000;”>,<span style=”background-color: #f5f5f5; color: #008000;”>//<span style=”background-color: #f5f5f5; color: #008000;”>是否全文搜索,否则只是前面作为标准
<span style=”background-color: #f5f5f5; color: #000000;”> scrollHeight: <span style=”background-color: #f5f5f5; color: #000000;”>300<span style=”background-color: #f5f5f5; color: #000000;”>,scroll: <span style=”background-color: #f5f5f5; color: #0000ff;”>true<span style=”background-color: #f5f5f5; color: #000000;”>,width: $(<span style=”background-color: #f5f5f5; color: #000000;”>”<span style=”background-color: #f5f5f5; color: #000000;”>#flxzTb<span style=”background-color: #f5f5f5; color: #000000;”>”<span style=”background-color: #f5f5f5; color: #000000;”>).width(),multiple: <span style=”background-color: #f5f5f5; color: #0000ff;”>false<span style=”background-color: #f5f5f5; color: #000000;”>,formatItem: <span style=”background-color: #f5f5f5; color: #0000ff;”>function<span style=”background-color: #f5f5f5; color: #000000;”> (row,i,max) { <span style=”background-color: #f5f5f5; color: #008000;”>//<span style=”background-color: #f5f5f5; color: #008000;”>显示格式
<span style=”background-color: #f5f5f5; color: #0000ff;”>return <span style=”background-color: #f5f5f5; color: #000000;”>”<span style=”background-color: #f5f5f5; color: #000000;”> <span style=”background-color: #f5f5f5; color: #000000;”>” <span style=”background-color: #f5f5f5; color: #000000;”>+ <span style=”background-color: #f5f5f5; color: #000000;”>”<span style=”background-color: #f5f5f5; color: #000000;”>[<span style=”background-color: #f5f5f5; color: #000000;”>” <span style=”background-color: #f5f5f5; color: #000000;”>+<span style=”background-color: #f5f5f5; color: #000000;”> row.XCODE <span style=”background-color: #f5f5f5; color: #000000;”>+ <span style=”background-color: #f5f5f5; color: #000000;”>”<span style=”background-color: #f5f5f5; color: #000000;”>]—<span style=”background-color: #f5f5f5; color: #000000;”>” <span style=”background-color: #f5f5f5; color: #000000;”>+<span style=”background-color: #f5f5f5; color: #000000;”> row.flmc <span style=”background-color: #f5f5f5; color: #000000;”>+ <span style=”background-color: #f5f5f5; color: #000000;”>”<span style=”background-color: #f5f5f5; color: #000000;”> <span style=”background-color: #f5f5f5; color: #000000;”>”<span style=”background-color: #f5f5f5; color: #000000;”>;
},formatMatch: <span style=”background-color: #f5f5f5; color: #0000ff;”>function<span style=”background-color: #f5f5f5; color: #000000;”> (row,max) { <span style=”background-color: #f5f5f5; color: #008000;”>//<span style=”background-color: #f5f5f5; color: #008000;”>以什么数据作为搜索关键词,可包括中文,
<span style=”background-color: #f5f5f5; color: #0000ff;”>return<span style=”background-color: #f5f5f5; color: #000000;”> row.flmc;
},formatResult: <span style=”background-color: #f5f5f5; color: #0000ff;”>function<span style=”background-color: #f5f5f5; color: #000000;”> (row) {
<span style=”background-color: #f5f5f5; color: #0000ff;”>return<span style=”background-color: #f5f5f5; color: #000000;”> row.flmc ; <span style=”background-color: #f5f5f5; color: #008000;”>//<span style=”background-color: #f5f5f5; color: #008000;”>返回结果
<span style=”background-color: #f5f5f5; color: #000000;”> }
});
});
}
}
});
}
<span style=”color: #0000ff;”></<span style=”color: #800000;”>script<span style=”color: #0000ff;”>>