Tags

,


Auto Complete with C# Static Method in .cs File

Step1:

<asp:ScriptManager ID=”ScriptManager1″ runat=”server” />

        <div>

            <asp:UpdatePanel ID=”UpdatePanel1″ runat=”server”>

                <ContentTemplate>

                    <asp:TextBox ID=”TextBox1″ runat=”server” AutoPostBack=”True”

                        ontextchanged=”TextBox1_TextChanged”></asp:TextBox>

                    <cc1:AutoCompleteExtender

                        ID=”AutoCompleteExtender1″

                        TargetControlID=”TextBox1″

                        ServiceMethod=”GetName”

                        runat=”server” CompletionInterval=”10″ MinimumPrefixLength=”2″ >

                    </cc1:AutoCompleteExtender>

                   

                    <asp:Label ID=”Label1″ runat=”server”></asp:Label>

                    

                </ContentTemplate>

            </asp:UpdatePanel>           

        </div>

 

 

 Step2:

[System.Web.Services.WebMethod]

    [System.Web.Script.Services.ScriptMethod]

    public static string[] GetName(string prefixText, int count)

    {

        string strQuery = “Select Name from Emp where Name like ‘” + prefixText + “%'”;

        string[] names = { “1. ” + prefixText, “2. ” + prefixText, “3. ” + prefixText, “4. ” + prefixText };

        return names;

    }

 

    protected void TextBox1_TextChanged(object sender, EventArgs e)

    {

        Label1.Text = TextBox1.Text;

    }

Advertisements