ajaxToolkit:AutoCompleteExtender 使用键值对
2011-05-22 08:24
381 查看
很奇怪为什么MS不把autocomplete封装成可以直接服务器端使用键值对,而要使用者自己定义客户端事件解决。。。。下面是网上看到的使用键值对方法,有空封装一下,嘿嘿
Howto:UseaKeyValuePairinyourAutoCompleteExtender(updatedagain...)
Hiall,
Thishascomeuptimeandagainontheasp.netAjaxforumsandhasbecometheTopVotedissuefortheAutoCompleteExtenderWorkItems.Ihadsometimetheotherdayandsetupontowriteafixforthis.
Howdoyouuseit?
1)AttachahandlertotheitemSelectedEventusingtheOnClientItemSelectedpropertyintheACEmarkup
2)TheServer-SideMethod:
TheServer-SideMethodwillreturnanarrayofstringsasbefore,
YoucreateKeyValuePairsbycallingthemethod:
EX:
DownloadtheLatestAjaxControlToolkitfrom:
http://www.codeplex.com/AtlasControlToolkit/Release/ProjectReleases.aspx?ReleaseId=4941
[Update]
Youdon'tneedtospecifytheUseKeyValuepairsattibuteanymore(infact,itsbeenremoved:)).
TheACEscriptisintelligentenoughtorealizewhenKey/Valuepairsarereturnedautomatically.
Andalso,themethodCreateKeyvaluePairhasbeenchangedtoCreateAutoCompleteItem.
Filedunder:JavaScript,AutoCompleteExtender
http://blogs.msdn.com/phaniraj/archive/2007/06/19/how-to-use-a-key-value-pair-in-your-autocompleteextender.aspx
http://spicydotnet.spaces.live.com/blog/cns!3810EC86F275BE32!174.entry?wa=wsignin1.0&sa=720268041
http://forums.asp.net/t/1162005.aspx
http://www.codeplex.com/AjaxControlToolkit/WorkItem/View.aspx?WorkItemId=9043
http://www.codeplex.com/AjaxControlToolkit/WorkItem/View.aspx?WorkItemId=12910
Howto:UseaKeyValuePairinyourAutoCompleteExtender(updatedagain...)
Hiall,Thishascomeuptimeandagainontheasp.netAjaxforumsandhasbecometheTopVotedissuefortheAutoCompleteExtenderWorkItems.Ihadsometimetheotherdayandsetupontowriteafixforthis.
Howdoyouuseit?
1)AttachahandlertotheitemSelectedEventusingtheOnClientItemSelectedpropertyintheACEmarkup
<ajaxToolkit:AutoCompleteExtenderrunat="server" BehaviorID="AutoCompleteEx"ID="autoComplete1" TargetControlID="myTextBox"ServicePath="~/Services/AutoComplete.asmx" ServiceMethod="GetCompletionListKeyValuePair" ...... OnClientItemSelected="IAmSelected" > </ajaxToolkit:AutoCompleteExtender>
functionIAmSelected(source,eventArgs){ alert("Key:"+eventArgs.get_text()+"Value:"+eventArgs.get_value()); }
2)TheServer-SideMethod:
TheServer-SideMethodwillreturnanarrayofstringsasbefore,
YoucreateKeyValuePairsbycallingthemethod:
AjaxControlToolkit.AutoCompleteExtender.CreateAutoCompleteItem(<key>,<value>);
EX:
[WebMethod] publicstring[]GetCompletionList(stringprefixText,intcount) { if(count==0) { count=10; } if(prefixText.Equals("xyz")) { returnnewstring[0]; } Randomrandom=newRandom(); List<string>items=newList<string>(count); for(inti=0;i<count;i++) { charc1=(char)random.Next(65,90); charc2=(char)random.Next(97,122); charc3=(char)random.Next(97,122); items.Add(AjaxControlToolkit.AutoCompleteExtender.CreateAutoCompleteItem(prefixText+c1+c2+c3,i.ToString())); } returnitems.ToArray(); }
TheDisplayoftheACEdoesnotchange,itstillremainsthesame:
OnceyouselectanitemfromtheDropDownoftheACE,yougetanalertwhichshowsyouthevalueoftheselectedItem.
InYourapplications,insteadoftheAlert,processsomebusinesslogicasperyourrequirements.
HopethisisanusefulAddition.
DownloadtheLatestAjaxControlToolkitfrom:
[Update]
Youdon'tneedtospecifytheUseKeyValuepairsattibuteanymore(infact,itsbeenremoved:)).
TheACEscriptisintelligentenoughtorealizewhenKey/Valuepairsarereturnedautomatically.
Andalso,themethodCreateKeyvaluePairhasbeenchangedtoCreateAutoCompleteItem.
Filedunder:
相关文章推荐
- ajaxToolkit:AutoCompleteExtender 使用键值对
- vs2005使用ajaxtoolkit:AutoCompleteExtender
- ajaxToolkit:AutoCompleteExtender 的触发选择事件以及JSON序列化和使用键值对
- Vs2008使用ajaxtoolkit:AutoCompleteExtender 1.0版本
- ajaxToolkit:AutoCompleteExtender 的触发选择事件以及JSON序列化和使用键值对
- ajaxToolkit:AutoCompleteExtender 的触发选择事件以及JSON序列化和使用键值 3ff8 对
- 使用AutoCompleteExtender控件实现自动完成
- asp.net ajax 使用AutoCompleteExtender开发自动完成功能(转载)
- 自动完成控件AutoCompleteExtender使用
- 15.AutoCompleteExtender的使用方法
- asp.net中使用AutoCompleteExtender具体方法
- asp.net ajax 使用AutoCompleteExtender开发自动完成功能
- 使用AutocompleteExtender无效或者没反应,输入啥都在webservice里面跟踪不到
- 使用AutocompleteExtender无效或者没反应的原因记录
- asp.net ajax 使用AutoCompleteExtender开发自动完成功能
- ajaxToolkit:AutoCompleteExtender 用法详解
- Ajax 中 AutoCompleteExtender 的使用
- Ajax的AutoCompleteExtender的使用
- AutoCompleteExtender 使用 滚动条效果
- ajaxToolkit:AutoCompleteExtender 用法详解