Sunday, January 31, 2010

AutoComplete Extender Without WebService

1. Creating a Common class file to GetAutoCompleteList items

public string[] GetAutoCompleteList(string strPrefix)
{
DataTable dt = new DataTable();
//Create [SP/Query] to Get the Items from Database
//Assume "dt" has got Records from Database
string[] items = new string[dt.Rows.Count];
int i = 0;
foreach (DataRow dr in dt.Rows)
{
items.SetValue(dr["COLNAME"].ToString(), i);
i++;
}
return items;
}


2. This Web Method can be created within the "page.aspx.cs" file.

[WebMethod]
public static string[] GetAutoCompleteItems(string prefixText)
{
ClsFile objFile = new ClsFile();
return objFile.GetAutoCompleteList(prefixText);
}
3. This following code is to be used in the "page.aspx" file

(Start Tag)asp:TextBox ID="txtListItems" AutoComplete="off" style="text-transform:capitalize" ToolTip="Enter List Item Prefix" Width="130px" runat="server" OnTextChanged=" txtListItems _TextChanged" AutoPostBack="True"(End Tag)
(Start Tag)cc1:AutoCompleteExtender ID=" txtListItems _AutoCompleteExtender" runat="server" ServiceMethod=" GetAutoCompleteItems " DelimiterCharacters=";, :" Enabled="True" TargetControlID=" txtListItems " MinimumPrefixLength="1" CompletionInterval="10" FirstRowSelected="true" EnableCaching="true" CompletionSetCount="12" (End Tag)

No comments:

Post a Comment