Ajax Auto Complete Extender

20 September, 2018

Related Blogs

Auto Complete Extender

Auto complete Extender is generally used with a text box control to provide a list of values from a database or any other data source to provide a list of values just below the list box  so that user can select a value from the list. It has the following important properties. target control ID Service Method : Used to specify the method name that returns the list of values to display for that target control Minimum prefix Length : Used to specify minimum number of characters to type within the target control to execute the service method and get list of values to display.  Example The following example demonstrates how to use auto complete extender control. Add a page to the website and place a Toolkit script manger and a Label and text box and for the label set the caption employee name and for the Textbox set the ID T1. Within HTML source of the page take one auto complete extender and set following properties for it. <asp : Auto completeExtender ID = “AutoCompleteExtendr1” runat=”server” TargetControlID=”T1” MinumumprefixLength=”1” service Method=”GetNames”  Useconnect key=”True”> </asp:AutoCompleteExtender> Within the design of that page click on the smart tag of text box control and choose “AutoCompleteMethod” to create the method “creatNames()” that is specified as service method for the autocomplete Extender and within that method write the following code. Under GetName() Sql connection Cn= new sqlconnection (“select Ename form Emp where Ename like” + prefixText+”%”,cn);; sqlDataReader Dr=cmd.ExecuteReader(); List<string> Names = new List <string > () ; while(Dr.Read()) { Names.Add(Dr[“Ename”].Tostring()); } Dr.close(); cn.close(); return Names.ToArray(); }