AJAX Autocomplete Extender using EDM

Code in ASPX page:
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<link href="StyleSheet.css" rel="stylesheet" type="text/css" />
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
<asp:TextBox ID="TextBox1" runat="server" Height="22px"
<cc1:AutoCompleteExtender ID="TextBox1_AutoCompleteExtender"
 runat="server" DelimiterCharacters=""
  Enabled="True" MinimumPrefixLength="1"
ServiceMethod="GetCompletionList" ServicePath=""
UseContextKey="True" CompletionInterval="10">
<asp:Button ID="btnSearch" runat="server"
onclick="btnSearch_Click" Text="Search" />
<asp:GridView ID="GridView1" runat="server"
CellPadding="4" ForeColor="#333333"
<AlternatingRowStyle BackColor="White" />
<EditRowStyle BackColor="#2461BF" />
<FooterStyle BackColor="#507CD1" Font-Bold="True"
ForeColor="White" />
<HeaderStyle BackColor="#507CD1" Font-Bold="True"
ForeColor="White" />
<PagerStyle BackColor="#2461BF" ForeColor="White"
HorizontalAlign="Center" />
<RowStyle BackColor="#EFF3FB" />
<SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True"
ForeColor="#333333" />
<SortedAscendingCellStyle BackColor="#F5F7FB" />
<SortedAscendingHeaderStyle BackColor="#6D95E1" />
<SortedDescendingCellStyle BackColor="#E9EBEF" />
<SortedDescendingHeaderStyle BackColor="#4870BE" />

Code behind:
[System.Web.Services.WebMethodAttribute(), System.Web.Script.Services.ScriptMethodAttribute()]
    public static string[] GetCompletionList(string prefixText, int count, string contextKey)
        DatabaseModel.DatabaseEntities obj = new DatabaseModel.DatabaseEntities();
        var x = (from n in obj.Items
                 where n.Description.ToUpper().Contains(prefixText.ToUpper())
                 select n.Description);
        return x.ToArray<string>();

    protected void btnSearch_Click(object sender, EventArgs e)
        DatabaseModel.DatabaseEntities obj = new DatabaseModel.DatabaseEntities();
        var x = (from n in obj.Items
                 where n.Description.ToUpper().Contains(TextBox1.Text.ToUpper())
                 select n);
       GridView1.DataSource = x;

Download Sample Code

One thought on “AJAX Autocomplete Extender using EDM

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s