来博客园很久了,一直是伸手党,呵呵,现在终于申请了一个账号并开通了博客

下面分享下之前在一个项目里遇到的问题

前段时间在一个项目里要求在文本框内输入要搜索的内容,自动提示与此内容相关的词条

当时在博客园里看到了(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服务实现文本框自动完成扩展的更多相关文章

  1. Web控件文本框Reset的功能

    在前一篇中<怎样实现Web控件文本框Reset的功能>http://www.cnblogs.com/insus/p/4120889.html Insus.NET只实现了文本框的功能.单个或 ...

  2. zabbix通过curl命令判断web服务是否正常并自动重启服务

    zabbix通过curl命令判断web服务是否正常并自动重启服务 主要思路: 通过curl命令获取服务器响应码,如果正常返回200,不正常返回000 具体命令: curl -I -s -w " ...

  3. 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.文件读取.可变参数.自动滚动 之前的介 ...

  4. 怎样实现Web控件文本框Reset的功能

    在ASP.NET开发过程序,在数据插入之后,文本框TextBox控件需要Reset.如果只有一两个文件框也许没有什么问题,如果网页上有很多文本框,你就会有点问题了.再加上某一情形,一些文本框是有默认值 ...

  5. web轻量级富文本框编辑

    前言 主要介绍squire,wangeditor富文本编辑 以及用原生js 如何实现多个关键字标识 需求 如何标记多个关键字,取消关键字 第一种方法 原生 textarea 标记 准备资料参考:张鑫旭 ...

  6. ASP.NET输入文本框自动提示功能

    在ASP.NET Web开发中会经常用到自动提示功能,比如百度搜索.我们只要输入相应的关键字,就可以自动得到相似搜索关键字的提示,方便我们快速的输入关键字进行查询. 那么在ASP.NET中,如果我们需 ...

  7. 基于JQuery实现的文本框自动填充功能

    1. 实现的方法 /* * js实现的文本框的自动完成功能 */ function doAutoComplete(textid,dataid,url){ $("#" + texti ...

  8. chrome下input文本框自动填充背景问题解决

    chrome下input文本框会自动填充背景,只需要给文本框加一个样式即可解决问题 input:-webkit-autofill {-webkit-box-shadow: 0 0 0px 1000px ...

  9. Chrome表单文本框自动填充黄色背景色样式

    chrome表单自动填充后,input文本框的背景会变成偏黄色的,这是由于chrome会默认给自动填充的input表单加上input:-webkit-autofill私有属性,然后对其赋予以下样式: ...

随机推荐

  1. yarn 集群部署,遇到的问题小结

    版本号信息: hadoop 2.3.0  hive 0.11.0 1. Application Master 无法訪问     点击application mater 链接,出现 http 500 错 ...

  2. 基于Android 平台简易即时通讯的研究与设计[转]

    摘要:论文简单介绍Android 平台的特性,主要阐述了基于Android 平台简易即时通讯(IM)的作用和功能以及实现方法.(复杂的通讯如引入视频音频等可以考虑AnyChat SDK~)关键词:An ...

  3. (转)如何在JavaScript与ActiveX之间传递数据3

    本文研究如何在JS等脚本语言与ActiveX控件之间通信,如何传递各种类型的参数,以及COM的IDispatch接口.使用类似的方法,可以推广到其他所有脚本型语言,如LUA,AutoCad等.本文将研 ...

  4. HIDKomponente使用读写Hid设备一瞥

    HIDKomponente 是delphi中使用的第三方Hid控件库,可以检测.控制连接到电脑的Hid设备.一般情况下多为usb设备.HIDKomponente的使用实际上很简单,只是因为第一次使用, ...

  5. java_实现接口的枚举类

    package ming; interface GenderDoc { void info(); } enum Gender implements GenderDoc { // public stat ...

  6. Top 10 Algorithms for Coding Interview--reference

    By X Wang Update History:Web Version latest update: 4/6/2014PDF Version latest update: 1/16/2014 The ...

  7. SQL Server 内存管理

    windows memory:  Memory: Cache Bytes 是系统的working set, 也就是系统使用的物理内存数目. 可以观察Windows用了多少物理内存. 1. System ...

  8. Matlab图像函数之pie

    一.pie pie用于描绘平面饼图. (1)pie(X) 利用向量X中的数据描绘饼图. 例如: X = [1, 1, 2, 2, 3, 4, 5]; pie(X) 得到 注意,X中的数据被看做频数,饼 ...

  9. JSON对象和string的相互转换

    JSON.stringify(obj) 将JSON转为字符串. JSON.parse(string) 将字符串转为JSON格式.

  10. HTML5拖拽功能drag

    1.创建拖拽对象 给需要拖拽的元素设置draggable属性,它有三个值: true:元素可以被拖拽:false:元素不能被拖拽:auto: 浏览器自己判断元素是否能被拖拽. 2.处理拖拽事件当我们拖 ...