Main menu:

 

August 2008
M T W T F S S
« Jul   Sep »
 123
45678910
11121314151617
18192021222324
25262728293031

Site search

Archives

Categories

Tags

Links:

Autocomplete ajax tool kit

Scenario

you have a global search box on your website and when you input the first character of the first name , all the words which starts with that particular word will be displayed in the list box. the good thing is that as its an ajax control,  its fast enough without the post back, its asynchronous.

resources required:

you will be required to add a webservice to your web application and if your code behind class name is autocomplete.cs then in the web service use CodeBehind=”~/AutoComplete.cs”

also be required to add the method.

////AutoComplete.cs

[WebMethod]
public string[] GetNameList(string prefixText, int count)
{
string strFirstName,strLastName
DataSet namesDataset =getAllNames(prefixText + “%”);
//getAllNames does database manupulation and get the records

List<string> items = new List<string>(count);
foreach (DataRow dRow in namesDataset .Tables[0].Rows)
{
strFirstName = Convert.ToString(dRow["FirstName"]);
strLastName = Convert.ToString(dRow["LastName"]);
items.Add(strFirstName + ” ” +  strLastName);
}

return items.ToArray();
}
///in ASPX Page

<ajaxToolkit:AutoCompleteExtender
runat=”server”
ID=”autoComplete1″
TargetControlID=”searchTextBox”
ServicePath=”../AutoComplete.asmx”
ServiceMethod=”GetNameList”
MinimumPrefixLength=”1″
CompletionInterval=”1000″
EnableCaching=”true”
CompletionSetCount=”12″ />
<asp:TextBox runat=”server” ID=”searchTextBox” CssClass=”input” AutoPostBack=”false” Width=”125px” autocomplete=”off” />

Comments

Comment from wholesale from china
Time August 14, 2008 at 10:59 am

Sandra Kellog wrote about it lately but i think what you wrote is much better.

Write a comment





Currently you have JavaScript disabled. In order to post comments, please make sure JavaScript and Cookies are enabled, and reload the page.