关于不使用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私有属性,然后对其赋予以下样式: ...
随机推荐
- 【转】bt协议的详细分析
转自:https://baoz.net/bt-protocol/ 一 BT系统的组成结构 1 普通的Web服务器: 例如Apache或IIS服务器 2 一个静态的种子文件: 即. ...
- Parse error: syntax error, unexpected T_PUBLIC in 问题解决
class 类中 public function _getInfo($sn){ $title = ''; $_array = explode('~', $sn); ...
- android自动打包方法(ant+proguard+签名)
前段时间做了一个android的网游项目,现在优化减少体积和防止别人反编译,需要把编译后.class进行混淆,开始在网上看了一些关于 ProGuard的介绍,基本上都是使用ADT自带的打包方式,那个打 ...
- 细说Java多线程之内存可见性
编程这些实践的知识技能,每一次学习使用可能都会有新的认识 一.细说Java多线程之内存可见性(数据挣用) 1.共享变量在线程间的可见性 共享变量:如果一个 ...
- zend studio快捷模板 开发工具之zend studio一些配置
以下是以Zend Studio 10.0.0版本为基础的: 模板的配置(template): [菜单]->[Window]->[preferences]->[PHP]->[Ed ...
- 【转】频点CTO张成:基于Cocos2d的MMORPG开发经验
http://www.9ria.com/plus/view.php?aid=27698 作者: zhiyuanzhe3 发表时间: 2013-06-29 17:46 6月29日,由9Tech社区.51 ...
- Templates
Templates Templates are the site's markup, where images and js, css files are located as well as the ...
- STC89C52单片机内部EEPROM驱动
STC89C52单片机自身带有4K的存储空间,分为8个扇区,每个扇区512字节,第一扇区起始地址为:0x2000, 结束地址为:21FF, 第八扇区起始地址为0x2E00,结束地址是2FFF #inc ...
- swift的特点
2个不需要: 1.不需要编写main函数:从上往下按顺序执行代码,所以最前面的代码会自动当做程序的入口 2.不需要在每一条语句后面加分号(也可以加):若是有多条语句在同一行就一定要加分号 ...
- CentOS7安装RabbitMQ集群
实验环境 RabbitMQ 集群 server1.example.com IP: 10.10.10.11 Node: diskserver2.example.com IP: 10.1 ...