关于不使用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私有属性,然后对其赋予以下样式: ...
随机推荐
- 【52】写了placement new也要写placement delete
1.Widget* pw = new Widget; 调用了两个方法:第一个方法是operator new 负责分配内存:第二个方法是在分配的内存上构造Widget,即调用Widget的default ...
- C++和python使用struct传输二进制数据结构来实现
网络编程问题往往涉及二进制数据的传输.在C++经常使用的传输是文本字符串和分组结构. 假设该数据可以预先送入连续的内存区域,然后让send函数来获得的第一个地址,这一块连续的内存区就能完成传输数据.文 ...
- 编程之linux与win区别
换行符在Linux和Windows下的区别 一.区别 换行符: 1.windows中的换行符是\r\n, 2. linux/unix下的换行符是\n. 其中: 回车符:\r=0x0d (13) ret ...
- iOS 如何进行逆向工程
原文:http://www.zhihu.com/question/20317296 季逸超,Peak-Labs创始人/CEO,猛犸浏览器.Rasgue- 有幸被邀请回答,不过不知道您要了解的'系统机制 ...
- Apache Rewrite 服务器变量
Apache提供给rewirte模块的环境变量大概分成5个类型. 第一部分: HTTP headers 部分参数 参数名称: HTTP_USER_AGENT 样例参考值: Mozilla/5.0 (W ...
- Jackson框架,json转换
Jackson可以轻松的将Java对象转换成json对象和xml文档,同样也可以将json.xml转换成Java对象. 前面有介绍过json-lib这个框架,在线博文:http://www.cnblo ...
- python生成简单的验证码
#coding=utf-8 from PIL import Image, ImageDraw, ImageFont, ImageFilter import random # 随机字母: def rnd ...
- jquery中的index方法
问题描述:灵活使用jquery中的index方法 方法签名:index([selector|element]) 用法概述:P1.index(P2) //调用者P1可以为对象或集合 参数为空,返回P1 ...
- D3中path各指令的含义
svg.append('path').attr({ id: 'mypath', d: 'M50 100Q350 50 350 250Q250 50 50 250' }) path 的指令有: 指令 参 ...
- tcpdf MultiCell line break
在程序中,我遇到MultiCell中显示三个字符串,开始时 $pdf->MultiCell(63.5, 30, $name."\n".$address."\n&qu ...