Using AutoCompleteExtender in asp.NET
//SERVICE Example: extenderService.asmx using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Services; using System.Web.Services.Protocols; /// <summary> /// Summary description for AutoCompleteService /// </summary> [WebService(Namespace = "http://tempuri.org/")] [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] [System.Web.Script.Services.ScriptService] // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. public class AutoCompleteService : System.Web.Services.WebService { public AutoCompleteService () { //Uncomment the following line if using designed components //InitializeComponent(); } [System.Web.Services.WebMethod] [System.Web.Script.Services.ScriptMethod] public string[] GetSubName(String prefixText) { DataClassesDataContext dc = new DataClassesDataContext(); return dc.SUB_TYPEs.Where(stype => stype.SUB.sub_name.StartsWith(prefixText)).OrderBy(stype => stype.SUB.sub_name).Select(stype => stype.SUB.sub_name).Take(12).ToArray(); } } //TEXTBOX declaration in any .aspx <asp:TextBox ID="TextBoxFilterTxt" runat="server" Width="712px"></asp:TextBox> <asp:AutoCompleteExtender ID="TextBoxFilterTxt_AutoCompleteExtender" runat="server" DelimiterCharacters="" Enabled="True" TargetControlID="TextBoxFilterTxt" ServicePath="~/AutoCompleteService.asmx" ServiceMethod="GetSubName" MinimumPrefixLength="3" CompletionSetCount="12" EnableCaching = "true" ShowOnlyCurrentWordInCompletionListItem="true"> <Animations> <OnShow> <Sequence> <OpacityAction Opacity="0" /> <HideAction Visible="true" /> <Parallel Duration=".1"> <FadeIn Duration=".5" Fps="20" /> </Parallel> </Sequence> </OnShow> <OnHide> <Parallel Duration=".4"> <FadeOut /> </Parallel> </OnHide> </Animations> </asp:AutoCompleteExtender> THIS IS IT)
Advertisement
Categories: ASP.net