欢迎您访问我爱IT技术网,今天小编为你分享的编程技术是:【Ajax+asp.net智能匹配检索(含图含完整代码)】,下面是详细的讲解!
Ajax+asp.net智能匹配检索(含图含完整代码)
using System;
using System.Web;
using System.Collections;
using System.Web.Services;
using System.Web.Services.Protocols;
//引入空间
using System.Data;
using System.Data.OleDb;
using System.Configuration;
/// <summary>
/// KeyFind 的摘要说明
/// </summary>
[WebService(Namespace="http://tempuri.org/")]
[WebServiceBinding(ConformsTo=WsiProfiles.BasicProfile1_1)]
//添加服务脚本(必须添,否则程序不能正常运行)
[System.Web.Script.Services.ScriptService]
public class KeyFind : System.Web.Services.WebService
{
public KeyFind()
{
//如果使用设计的组件,请取消注释以下行
//InitializeComponent();
}
//定义数组保存获取的内容
private string[] autoCompleteWordList=null;
//两个参数“prefixText”表示用户输入的前缀,count表示返回的个数
[WebMethod]
public String[] GetCompleteDepart(string prefixText, int count)
{
///检测参数是否为空
if (string.IsNullOrEmpty(prefixText)==true || count <=0) return null;
// 如果数组为空
if (autoCompleteWordList==null)
{
//读取数据库的内容
OleDbConnection conn=new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Server.MapPath("Ex18_02.mdb"));
conn.Open();
OleDbDataAdapter da=new OleDbDataAdapter("select keyName from keyInfo where keyName like'" + prefixText + "%' order by keyName", conn);
DataSet ds=new DataSet();
da.Fill(ds);
//读取内容文件的数据到临时数组
string[] temp=new string[ds.Tables[0].Rows.Count];
int i=0;
foreach (DataRow dr in ds.Tables[0].Rows)
{
temp[i]=dr["keyName"].ToString();
i++;
}
Array.Sort(temp, new CaseInsensitiveComparer());
//将临时数组的内容赋给返回数组
autoCompleteWordList=temp;
if (conn.State==ConnectionState.Open)
conn.Close();
}
//定位二叉树搜索的起点
int index=Array.BinarySearch(autoCompleteWordList, prefixText, new CaseInsensitiveComparer());
if (index < 0)
{ //修正起点
index=~index;
}
//搜索符合条件的数据
int matchCount=0;
for (matchCount=0; matchCount < count && matchCount + index < autoCompleteWordList.Length; matchCount++)
{ ///查看开头字符串相同的项
if (autoCompleteWordList[index + matchCount].StartsWith(prefixText, StringComparison.CurrentCultureIgnoreCase)==false)
{
break;
}
}
//处理搜索结果
string[] matchResultList=new string[matchCount];
if (matchCount > 0)
{ //复制搜索结果
Array.Copy(autoCompleteWordList, index, matchResultList, 0, matchCount);
}
return matchResultList;
}
}
关于Ajax+asp.net智能匹配检索(含图含完整代码)的用户互动如下:
相关问题:关于asp.net+ajax的简单实例代码
答: $.ajax({ type: "post", url: "ajax.aspx", dataType: "html", data: {type:getimg}, success: function (result) { $("#img").attr({"src":result}); } });这只是你前太代码的,不知道你服务端什么情况 还有 切换一个图 干嘛弄这么麻烦呢…… >>详细
相关问题:有ajax+asp.net的实例代码吗?求一段ajax+asp.net...
答:从网上搜索吧,好多的。通过一个局部更新的例子,就能入门。 >>详细
相关问题:asp.net Ajax 后台调用Js,部分Cs代码不执行问题,高...
答: loginName: password: $(document).ready(function(){ $("input[type=button]").click(function(){ $.post("login.aspx",{loginname:$("#txtLoginName").val(),password:$("#txtPassword").val()},function(data){ if(data=="成功"){ $("#login... >>详细
- 【asp】asp.net url重写浅谈-net-url重写
- 【DataSet】DataSet、DataTable、DataRow区别详解
- 【asp】asp.net 动态添加多个用户控件-net-动态添
- 【ASP】ASP.NET中内嵌页面代码的一个问题-NET-内
- 【As】Asp.net中的页面乱码的问题-sp--pn-ne-et
- 【创建】ASP.NET Web API教程 创建域模型的方法详
- 【Asp】Asp.net 页面调用javascript变量的值-net-
- 【ASP】ASP.NET 5升级后如何删除旧版本的DNX-NET5
- 【404页面】ASP.NET设置404页面返回302HTTP状态码
- 【asp】asp.net开发中常见公共捕获异常方式总结(
- 评论列表(网友评论仅供网友表达个人看法,并不表明本站同意其观点或证实其描述)
-
