This Functionality is called as AutoComplete TextBox
in asp.net 3.5 it supports AjaxControlToolKit which is open source & can be used in ur application.
First Download AjaxControlToolKit from Following Location.
http://ajaxcontroltoolkit.codeplex.com/[
^]
Then in ur asp.net bin Folder Copy the dll of AjaxControlToolKit.
& add Following Line of code at top of ur asp.net page.
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>
Add ScriptManager to page, Which required for Ajax Application.
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
Add One WebService file(.asmx) into ur project.
after adding .asmx file .cs file will saved in App_code Folder. add this type of method in .cs file.
[WebMethod(EnableSession = true)]
public string[] ItemName(string prefixText,int count)
{
int branchId = (int)Session["BranchId"];
using (var db = new WanaDCDataContext())
{
var items = new List<String>();
JavaScriptSerializer serailizer = new JavaScriptSerializer();
var list = (from it in db.ItemMasters where it.BranchId == branchId && (it.ItemName).ToLower().StartsWith(prefixText) orderby it.ItemName ascending select it).Take(count);
foreach (ItemMaster c in list)
{
var html = c.ItemId;
string item = AutoCompleteExtender.CreateAutoCompleteItem(c.ItemName, serailizer.Serialize(html));
items.Add(item);
}
return items.ToArray();
}
}
This is Web Service Methods Which Returns String array. i have used linq To SQL Classes to retrieve data from Database.
Then call this web service from asp.net page as below.
<cc1:AutoCompleteExtender ID="AutoCompleteExtender1" TargetControlID="txtStkItem"
OnClientItemSelected="OnItemSelected" CompletionSetCount="60" ServiceMethod="ItemName"
ServicePath="AjaxAutoCompleteService.asmx" MinimumPrefixLength="1" CompletionInterval="100"
CompletionListCssClass="completionList" CompletionListItemCssClass="listItem"
CompletionListHighlightedItemCssClass="itemHighlighted" runat="server">
</cc1:AutoCompleteExtender>
Make Sure You specify correct service Method,Service Path. reply for any difficulty.
Thanks & Regards,
satya.