- How To Ajax control toolkit Auto complete uses
Database connection Path
in web.config Write the database pate
<connectionStrings>
<add name="SurveyConnectionString" connectionString="Data Source=mohit\SQLEXPRESS;Initial Catalog=sqldb;Integrated Security=True" providerName="System.Data.SqlClient"/>
</connectionStrings>
(Ritu.aspx) Aspx File (HTML Files)
(1) include Ajex Liberary
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajax" %>
(2) Add Script Manager
<ajax:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server" EnablePageMethods="true" > </ajax:ToolkitScriptManager>
(3) Add Auto complete Control
<asp:TextBox ID="txt_Place" runat="server" />
<ajax:AutoCompleteExtender ID="AutoCompleteExtender2" EnableCaching="true"
BehaviorID="AutoCompleteCities" TargetControlID="txt_Place"
ServiceMethod="GetCities" MinimumPrefixLength="3"
CompletionSetCount="10" runat="server" FirstRowSelected="true" UseContextKey="True" >
</ajax:AutoCompleteExtender>
((autocolplete.aspx.cs) .cs File (code behind file)
[System.Web.Services.WebMethod]
[System.Web.Script.Services.ScriptMethod]
public static string[] GetCities(string prefixText)
{
String strConnString = ConfigurationManager.ConnectionStrings["SurveyConnectionString"].ConnectionString;
SqlConnection con = new SqlConnection(strConnString);
con.Open();
string strQuery = "SELECT distinct [Sp_Location] FROM [Tbl_ShippingPrice] where Sp_Location like '" + prefixText + "%'";
DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter(strQuery, con);
da.Fill(ds);
con.Close();
List<string> cityList = new List<string>();
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
cityList.Add(ds.Tables[0].Rows[i][0].ToString());
}
return cityList.ToArray();
}