关于不使用web服务实现文本框自动完成扩展
来博客园很久了,一直是伸手党,呵呵,现在终于申请了一个账号并开通了博客
下面分享下之前在一个项目里遇到的问题
前段时间在一个项目里要求在文本框内输入要搜索的内容,自动提示与此内容相关的词条
当时在博客园里看到了(http://www.cnblogs.com/insus/archive/2013/03/28/2986217.html)这篇文章觉得挺好,我也就按照这样的方法去做了
在逻辑层我写两个一个类,去跟数据层交互
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using Bthinking.PlatForm.SystemManage.BLL;
using Bthinking.PlatForm.SystemManage.Model; /// <summary>
///ActiveDirectoryInfo 的摘要说明
/// </summary>
public class ActiveDirectoryInfo
{
Dim_RessellorInfoBLL bll_RessellorInfo = new Dim_RessellorInfoBLL();
public ActiveDirectoryInfo()
{
//
//TODO: 在此处添加构造函数逻辑
//
}
public DataTable GetDisplayName(string prefixText,int count)
{
Dim_RessellorInfoParameters para_RessellorInfo = new Dim_RessellorInfoParameters();
para_RessellorInfo.RessellorName = prefixText;
Dim_RessellorInfoCollection ressellorCollection = new Dim_RessellorInfoCollection();
ressellorCollection = bll_RessellorInfo.GetAllDim_RessellorInfos(para_RessellorInfo,,count);
DataTable ret = new DataTable();
ret = ressellorCollection.ToDataTable();
return ret;
} public int GetDisplayCount(string prefixText, int count)
{
Dim_RessellorInfoParameters para_RessellorInfo = new Dim_RessellorInfoParameters();
para_RessellorInfo.RessellorName = prefixText;
count = bll_RessellorInfo.GetRecordCount(para_RessellorInfo);
return count;
}
}
BLL
把一下代码拉至aspx页面
<ajaxToolkit:ToolkitScriptManager ID="ToolkitScriptManager" runat="server"></ajaxToolkit:ToolkitScriptManager>
在对应控件出引入如下代码
<asp:TextBox ID="TxtRessellorName" runat="server" Height="21px" Width="188px"></asp:TextBox>
<ajaxToolkit:AutoCompleteExtender
ID="AutoCompleteExtender1" runat="server" MinimumPrefixLength = ""
CompletionInterval = "" EnableCaching ="true" CompletionSetCount = "" TargetControlID="TxtRessellorName" ServiceMethod="GetDisplayUserName">
</ajaxToolkit:AutoCompleteExtender>
这里的ServiceMethod="GetDisplayUserName"对应CS中的方法 红色的部分必须添加
[System.Web.Services.WebMethod]
[System.Web.Script.Services.ScriptMethod]
public static string[] GetDisplayUserName(string prefixText, int count)
{
ActiveDirectoryInfo objActiveDirectoryInfo = new ActiveDirectoryInfo();
count = objActiveDirectoryInfo.GetDisplayCount(prefixText, count);
DataTable dt = objActiveDirectoryInfo.GetDisplayName(prefixText, count);
string[] strArray = new string[count];
int i = ;
foreach (DataRow dataRow in dt.Rows)
{
//array.Add(dataRow["RessellorName"].ToString());
strArray[i] = dataRow["RessellorName"].ToString();
i++;
} //return (string[])array.ToArray(typeof(string));
return strArray;
}
}
效果如下

总体来说,效果还是不错的,但是对于大数据量的词条筛选可能就显得有点鸡肋了
关于不使用web服务实现文本框自动完成扩展的更多相关文章
- Web控件文本框Reset的功能
在前一篇中<怎样实现Web控件文本框Reset的功能>http://www.cnblogs.com/insus/p/4120889.html Insus.NET只实现了文本框的功能.单个或 ...
- zabbix通过curl命令判断web服务是否正常并自动重启服务
zabbix通过curl命令判断web服务是否正常并自动重启服务 主要思路: 通过curl命令获取服务器响应码,如果正常返回200,不正常返回000 具体命令: curl -I -s -w " ...
- Creating Dialogbased Windows Application (4) / 创建基于对话框的Windows应用程序(四)Edit Control、Combo Box的应用、Unicode转ANSI、Open File Dialog、文件读取、可变参数、文本框自动滚动 / VC++, Windows
创建基于对话框的Windows应用程序(四)—— Edit Control.Combo Box的应用.Unicode转ANSI.Open File Dialog.文件读取.可变参数.自动滚动 之前的介 ...
- 怎样实现Web控件文本框Reset的功能
在ASP.NET开发过程序,在数据插入之后,文本框TextBox控件需要Reset.如果只有一两个文件框也许没有什么问题,如果网页上有很多文本框,你就会有点问题了.再加上某一情形,一些文本框是有默认值 ...
- web轻量级富文本框编辑
前言 主要介绍squire,wangeditor富文本编辑 以及用原生js 如何实现多个关键字标识 需求 如何标记多个关键字,取消关键字 第一种方法 原生 textarea 标记 准备资料参考:张鑫旭 ...
- ASP.NET输入文本框自动提示功能
在ASP.NET Web开发中会经常用到自动提示功能,比如百度搜索.我们只要输入相应的关键字,就可以自动得到相似搜索关键字的提示,方便我们快速的输入关键字进行查询. 那么在ASP.NET中,如果我们需 ...
- 基于JQuery实现的文本框自动填充功能
1. 实现的方法 /* * js实现的文本框的自动完成功能 */ function doAutoComplete(textid,dataid,url){ $("#" + texti ...
- chrome下input文本框自动填充背景问题解决
chrome下input文本框会自动填充背景,只需要给文本框加一个样式即可解决问题 input:-webkit-autofill {-webkit-box-shadow: 0 0 0px 1000px ...
- Chrome表单文本框自动填充黄色背景色样式
chrome表单自动填充后,input文本框的背景会变成偏黄色的,这是由于chrome会默认给自动填充的input表单加上input:-webkit-autofill私有属性,然后对其赋予以下样式: ...
随机推荐
- 网络防火墙实战-基于pfsense(1)
pfSense是一个免费的,开源的FreeBSD作为防火墙和路由器专为使用自定义版本.除了 是一个功能强大的,灵活的防火墙和路由平台,它包括一个长长的清单相关的功能,并允许进一步的扩展包,不添加膨胀和 ...
- 数据持久化(五)之CoreData
@简单的说,Core Data就是能够存储到磁盘的对象图,[...]Core Data能够帮我们做非常多任务作.它能够作为软件的整个模型层. 它不只在磁盘上存储数据.也把我们须要的数据对象读取到内存中 ...
- string中find函数的使用
9.47 编写程序,首先查找string"ab2c3d7R4E6"中的每个数字字符,然后查找其中每个字母字符.编写两个版本的程序,第一个要使用find_first_of,第二个要使 ...
- Android 带进度的圆形进度条
最近项目有个需求,做带进度从下到上的圆形进度条. 网上查了一下资料,发现这篇博客写得不错http://blog.csdn.net/xiaanming/article/details/10298163 ...
- requestCode 和 resultCode .
OK,代码如上,可能这个时候还会有点疑问,关于参数的疑问.直接看android sdk 帮助说得更清楚.我发现网上有些文章还有吧 requestCode 和 resultCode 混淆说明错的. st ...
- combo参数配置_手册
combotree : 设置为多选框: $('#menu-combotree').combotree({multiple:true}).combotree('loadData', menuListJs ...
- PHP端验证代码、后端验证
/** * 验证url是否存在 * @param string $url url路径 * @return boolean true:存在,false:不存在 */ public function va ...
- VS版本下载
tfs2012:BVGTF-T7MVR-TP46H-9Q97G-XBXRB http://www.microsoft.com/zh-cn/download/details.aspx?id=30658 ...
- Android 自学之基本界面组件(下)
按钮(Button)与图片按钮(ImageButton)组件的功能和用法 Button继承了TextView,ImageButton继承了Button.不管是Button还是ImageButton,他 ...
- Spring 的@Controller 和@RestController的区别
@RestController Spring 4.0中新增的特性 @RestController 继承自 @Controller,相当于@ResponseBody + @Controller 1. ...