posted 2/10/2009 by Vinay Gupta
I have seen that lot of my friends having problem in implementing the autoextender.
so that i have tried to describe that how to implement it.it may make easier to implement autoextender. Step1:Add required controls
<asp:TextBox ID="txtname" runat="server"/> <ajaxToolkit:AutoCompleteExtender ID="aceName" Enabled="true" runat="server" MinimumPrefixLength="1" TargetControlID="txtname" CompletionSetCount="20" CompletionInterval="0000" EnableCaching="true" ServiceMethod="GetName" ServicePath="AutoExtender.asmx"/>
<ajaxToolkit:AutoCompleteExtender ID="aceName" Enabled="true" runat="server" MinimumPrefixLength="1" TargetControlID="txtname" CompletionSetCount="20" CompletionInterval="0000" EnableCaching="true"
ServiceMethod="GetName" ServicePath="AutoExtender.asmx"/>
Note: please make sure you have given the virtual path of web service and name of web method correctly.Step2:Create the web service
public class AutoExtender : System.Web.Services.WebService { [WebMethod] public string[] GetName(string prefixText) { List<string> listString = new List<string>(); using (SqlConnection con = new SqlConnection("Initial Catalog=Dbname;Server=.;User ID=sa;Password=pwd")) { SqlCommand cm = new SqlCommand("SELECT Name,ID FROM tblUser Where Name like '" + prefixText + "%'", con); con.Open(); SqlDataReader dr = cm.ExecuteReader(); if (dr.HasRows) { while (dr.Read()) { listString.Add(AutoCompleteExtender.CreateAutoCompleteItem(dr["Name"].ToString(), dr["ID"].ToString())); //c.FullName, serializer.Serialize(c)) } } } string[] str = listString.ToArray(); return str; } }
List<string> listString = new List<string>(); using (SqlConnection con = new SqlConnection("Initial Catalog=Dbname;Server=.;User ID=sa;Password=pwd")) { SqlCommand cm = new SqlCommand("SELECT Name,ID FROM tblUser Where Name like '" + prefixText + "%'", con); con.Open(); SqlDataReader dr = cm.ExecuteReader(); if (dr.HasRows) { while (dr.Read()) { listString.Add(AutoCompleteExtender.CreateAutoCompleteItem(dr["Name"].ToString(), dr["ID"].ToString()));
//c.FullName, serializer.Serialize(c)) } } } string[] str = listString.ToArray(); return str; }
}
Hope this will help..
What kind of email newsletter would you prefer to receive from CodeAsp.Net?18