Welcome to RP's venture...Here you can find some of the relative topics like ASP.Net, C#.Net,VB.Net, SQL Server, AJAX, Javascripts, Sharepoint, WPF, WCF, Silverlight, MVC, General knowledge, Jokes, Fun, Technical, Non-Technical etc.
0

Auto Complete Suggest TextBox in ASP.Net

Posted by Rajendra Prasad Panchati on Thursday, March 25, 2010
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.

|

0 Comments

About Me