ajaxToolKit autoCompleteExtender简单例子

ajaxToolKit中有个autoCompleteExtender对TextBox的扩展,能实现在文本框输入时有下拉框提示。效果不错。使用AjaxToolKit需要安装asp.net的ajax扩展工具:官方文档,然后引用DLL。前台如下:

 
  
< asp:TextBox ID ="txtID" runat ="server" ></ asp:TextBox >
< asp:AutoCompleteExtender ID ="AutoCompleteExtender1" runat ="server"
TargetControlID
="txtID"
ServicePath
="autoCompExtenderServer.asmx"
ServiceMethod
="GetData"
CompletionSetCount
="10"
FirstRowSelected
="true"
MinimumPrefixLength
="1"
>
</ asp:AutoCompleteExtender >

 

其中TargetControlID表示绑定的TextBox

ServicePath:服务路径

ServiceMethod:自动提示的方法名

CompletionSetCount:显示的条数

FirstRowSelected:是否自动选择到提示的第一行

MinimumprefixLength:输入多少个字时开始提示;

 

autoCompExtenderServer.asmx后台代码

 
  
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Runtime.Serialization;
using System.Web.Script.Serialization;
namespace auotoCompleteText
{
/// <summary>
/// autoCompExtenderServer 的摘要说明
/// </summary>
[WebService(Namespace = " http://tempuri.org/ " )]
[WebServiceBinding(ConformsTo
= WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(
false )]
// 若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务,请取消对下行的注释。
[System.Web.Script.Services.ScriptService]
public class autoCompExtenderServer : System.Web.Services.WebService
{

[WebMethod]
public string [] GetData( string prefixText, int count)
{
string [] data = new string [ 10000 ];
for ( int i = 0 ; i < data.Length; i ++ )
data[i]
= i.ToString( " 0000 " );
return data.Where(p => p.IndexOf(prefixText) >= 0 ).Take(count).ToArray();
}
}
}

 

注意这里的两个参数:prefixText,count都不能改变。

 

 

参考资料:http://moosdau.blog.163.com/blog/static/43711282008824113942459/

 

转载于:https://www.cnblogs.com/xinjian/archive/2010/11/24/1886283.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值