At page directive
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajaxToolkit" %>
Controls needed at designing page
<asp:TextBox runat="server" ID="myTextBox" Width="300" autocomplete="off" />
<ajaxToolkit:AutoCompleteExtender runat="server" ID="autoComplete1" TargetControlID="myTextBox"
ServicePath="myWebService.asmx" ServiceMethod="GetDestinationNames" MinimumPrefixLength="1"
CompletionInterval="1000" EnableCaching="true" CompletionSetCount="12" />
Add a Web Service and add code to get your required data
public string[] GetDestinationNames(string prefixText, int count)
{
string Query = "SELECT * From YourTable where column like '%" + prefixText + "%'";
OdbcDataAdapter da = new OdbcDataAdapter(new OdbcCommand(Query, con));
DataSet ds = new DataSet();
da.Fill(ds);
string[] strArr = new string[ds.Tables[0].Rows.Count];
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
strArr[i] = ds.Tables[0].Rows[i]["city_name"].ToString();
}
return strArr;
}
Finally you can get fully working auto suggest textbox.
|