AutoCompleteExtender 使用示例
绑定 KeyValuePair,网上很多例子,没有找到绑定键值对的,msdn上有例子,备忘一下。
using FirstElite.Verify.Entity;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.Services; namespace FirstElite.Verify.WebServices
{
/// <summary>
/// SchoolAutoComplete 的摘要说明
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.Web.Script.Services.ScriptService]
public class SchoolAutoComplete : System.Web.Services.WebService
{ [WebMethod]
public string[] GetSchoolCompletionList(string prefixText, int count)
{
using (var db = new FirstEliteVerifyEntities())
{
var districtList = db.District.ToList();
var schoolList = db.School.Where(item => item.name.Contains(prefixText)).Take().OrderBy(item => item.districtcode)
.Select(item => new SchoolModel
{
Name = item.name,
DistrictCode = item.districtcode,
Code = item.schoolcode
}).ToList();
var sb = new StringBuilder();
foreach (var school in schoolList)
{
var districtCode = school.DistrictCode;
var district = districtList.FirstOrDefault(d => d.code == districtCode);
sb.Clear();
sb.Append(district.name);
while (district != null && district.parentcode != null)
{
district = districtList.First(item => item.code == district.parentcode);
if (district != null)
sb.Insert(, district.name);
}
school.District = sb.ToString();
} var result = schoolList.Select(item =>
{
var text = string.Format("{0}({1})", item.Name, item.District);
var autoCompleteItem = AjaxControlToolkit.AutoCompleteExtender.CreateAutoCompleteItem(text, item.Code);
return autoCompleteItem;
}); return result.ToArray();
}
} public class SchoolModel
{
public string Name { get; set; }
public string DistrictCode { get; set; }
public string District { get; set; }
public string Code { get; set; }
}
}
}
<asp:TextBox ID="txtSearchKey" runat="server" Width="200px" autocomplete="off"></asp:TextBox>
<ajaxToolkit:AutoCompleteExtender
runat="server"
BehaviorID="AutoCompleteEx"
ID="autoComplete1"
TargetControlID="txtSearchKey"
ServicePath="../WebServices/SchoolAutoComplete.asmx"
ServiceMethod="GetSchoolCompletionList"
MinimumPrefixLength="1"
CompletionInterval="500"
EnableCaching="true"
CompletionSetCount="50"
CompletionListCssClass="a"
CompletionListItemCssClass="b"
CompletionListHighlightedItemCssClass="c"
OnClientItemSelected="AutoCompleteSelected"
ShowOnlyCurrentWordInCompletionListItem="true" >
</ajaxToolkit:AutoCompleteExtender>
<script type="text/javascript">
function AutoCompleteSelected(source, eventArgs)
{
alert(eventArgs.get_text() + "<->" + eventArgs.get_value());
}
</script>
AutoCompleteExtender 使用示例的更多相关文章
- Swift3.0服务端开发(一) 完整示例概述及Perfect环境搭建与配置(服务端+iOS端)
本篇博客算是一个开头,接下来会持续更新使用Swift3.0开发服务端相关的博客.当然,我们使用目前使用Swift开发服务端较为成熟的框架Perfect来实现.Perfect框架是加拿大一个创业团队开发 ...
- .NET跨平台之旅:将示例站点升级至 ASP.NET Core 1.1
微软今天在 Connect(); // 2016 上发布了 .NET Core 1.1 ,ASP.NET Core 1.1 以及 Entity Framework Core 1.1.紧跟这次发布,我们 ...
- 通过Jexus 部署 dotnetcore版本MusicStore 示例程序
ASPNET Music Store application 是一个展示最新的.NET 平台(包括.NET Core/Mono等)上使用MVC 和Entity Framework的示例程序,本文将展示 ...
- WCF学习之旅—第三个示例之四(三十)
上接WCF学习之旅—第三个示例之一(二十七) WCF学习之旅—第三个示例之二(二十八) WCF学习之旅—第三个示例之三(二十九) ...
- JavaScript学习笔记(一)——延迟对象、跨域、模板引擎、弹出层、AJAX示例
一.AJAX示例 AJAX全称为“Asynchronous JavaScript And XML”(异步JavaScript和XML) 是指一种创建交互式网页应用的开发技术.改善用户体验,实现无刷新效 ...
- XAMARIN ANDROID 二维码扫描示例
现在二维码的应用越来越普及,二维码扫描也成为手机应用程序的必备功能了.本文将基于 Xamarin.Android 平台使用 ZXing.Net.Mobile 做一个简单的 Android 条码扫描示 ...
- iOS之ProtocolBuffer搭建和示例demo
这次搭建iOS的ProtocolBuffer编译器和把*.proto源文件编译成*.pbobjc.h 和 *.pbobjc.m文件时,碰到不少问题! 搭建pb编译器到时没有什么问题,只是在把*.pro ...
- Android种使用Notification实现通知管理以及自定义通知栏(Notification示例四)
示例一:实现通知栏管理 当针对相同类型的事件多次发出通知,作为开发者,应该避免使用全新的通知,这时就应该考虑更新之前通知栏的一些值来达到提醒用户的目的.例如我们手机的短信系统,当不断有新消息传来时,我 ...
- oracle常用函数及示例
学习oracle也有一段时间了,发现oracle中的函数好多,对于做后台的程序猿来说,大把大把的时间还要学习很多其他的新东西,再把这些函数也都记住是不太现实的,所以总结了一下oracle中的一些常用函 ...
随机推荐
- redis应用--位图
在我们平时开发过程中,会有一些 bool 型数据需要存取,比如用户一年的签到记录,签了是 1,没签是 0,要记录 365 天.如果使用普通的 key/value,每个用户要记录 365 个,当用户上亿 ...
- @EnableHystrix
@EnableHystrix 启动熔断降级服务 @Component把普通的pojo类实例到spring容器中去,相当于配置文件中的<bean id="" class=&qu ...
- (2018 Multi-University Training Contest 2)Problem G - Naive Operations
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6315 题目大意:告诉你a,b两个数组,a数组初始化为0,b数组告诉你长度和具体值,接下来有q次操作,a ...
- pyCharm中BeautifulSoup应用
BeautifulSoup 是第三方库的工具,它包含在一个名为bs4的文件包中,需要额外安装,安装方式 非常简单,进入python的安装目录,再进入scripts子目录,找到pip程序, pip in ...
- 如何验证代理ip的正确性
python requests 使用代理的话: proxy_list = ["aabbcc.aabbcc.169.aabbcc:8080", ] ip_p = random.cho ...
- 1—ARM中的寄存器
ARM共有37个寄存器.其中31个通用寄存器和6个状态寄存器. 一般通用寄存器R0-R12 R0-7为未分组寄存器:R8-12为分组寄存器. 未分组寄存器:在任何模式下,指向的都是同一个32位的物理寄 ...
- Python第二章(北理国家精品课 嵩天等)
一.深入理解Python语言 语法简洁 >13万第三方库 二.Python蟒蛇绘制 #PythonDraw.py import turtle turtle.setup(650,350,200,2 ...
- 安装linux虚拟机配置静态ip(NAT模式)
1.centOs7.VMware Workstation14 2.常规配置硬件和基本信息后,在图形安装界面将以太网链接打开,安装后配置ifcfg-e****,这里是我的配置文件 修改BOOTPROTO ...
- github项目
一.github项目地址: https://github.com/fairy1231/gitLearning/tree/master 二.github的重要性: Git 是一个快速.可扩展的分布式版本 ...
- 2019 Power BI最Top50面试题,助你面试脱颖而出系列<下>
Q:什么是附加题? A:这就是常说的送分可选题,可做可不做:也可以说是加分项,是难点提升题. Power BI 面试题 — 附加题 33)什么是 Power View? 答案: Power View是 ...