关于不使用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私有属性,然后对其赋予以下样式: ...
随机推荐
- jQuery操作select option
jQuery获取Select选择的Text和Value: 1. var checkText=jQuery("#select_id").find("option:selec ...
- file_put_contents() failed to open stream: Permission denied 问题解决
很长时间没有写PHP了,今天突然有个需求要写一个保存文件的功能. function downloadFile( $url , $savePath = '' ) { $fileName = ge ...
- C++中的new与delete总结
1. operator new.operator delete与new.delete操作符的区别: operator new的作用类似于malloc,负责分配内存:operator delete的作用 ...
- Funambol Developer's Guide 中 connector development样例的问题
今天学习Funambol的connector开发,官方文档中的样例有问题. 首先,文档中提供的maven命令不可用: mvn archetype:generate -DarchetypeGroupId ...
- [React Fundamentals] State Basics
State is used for properties on a component that will change, versus static properties that are pass ...
- [React Native] Create a component using ScrollView
To show a list of unchanging data in React Native you can use the scroll view component. In this les ...
- 信号之kill和raise函数
kill函数将信号发送给进程或进程组.raise函数则允许进程向自身发送信号. #include <signal.h> int kill(pid_t pid, int signo); in ...
- Mysql在windows下的免安装配置步骤和重新安装的步骤
windows下mysql免安装配置 1. 下载mysql免安装压缩包 下载mysql-5.6.22-winx64.zip 解压到本地D:\mysql-5.6.22-winx64 2. 修改配置文件 ...
- MySQL(6):数据操作
1.创建数据(插入数据) (1)insert into tab_name(字段列表) values(值列表) (2)如果需要在插入时,为所有的字段设置值,那么可以省略字段列表.要求是值的顺序,应该 ...
- Lucene 索引功能
Lucene 数据建模 基本概念 文档(doc): 文档是 Lucene 索引和搜索的原子单元,文档是一个包含多个域的容器. 域(field): 域包含“真正的”被搜索的内容,每一个域都有一个标识名称 ...