Skip to content

Ediatble Textbox in asp.net

Shubhangi Indalkar

Asked Oct 10, 2013, 2:04 AM EDT1 answer
Share
LinkedInX
I want to editable textbox with it's dropdown list in asp.net.
suppose I add 'a' letter in textbox then listout word from db those start in 'a' letter.Similarly in google search textbox.

1 Answer

Know the answer? Post it. Somebody with the same question will find it here.

  • Anil  Kumar
    0

    ASPX Page  

      
    <%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajax" %>  

    <head runat="server">  

    <title>Ajax AutoCompleteExtender without Webservice</title>  

    </head>  

    <body>  

    <form id="form1" runat="server">  

    <ajax:ToolkitScriptManager ID="ScriptManager1" runat="server"/>  

    <div>  

    <asp:TextBox ID="txtCountry" runat="server"></asp:TextBox>  

    <ajax:AutoCompleteExtender ID="AutoCompleteExtender1" runat="server" TargetControlID="txtCountry"  

    MinimumPrefixLength="1" EnableCaching="true" CompletionSetCount="1" CompletionInterval="1000"ServiceMethod="GetCountries" >  

    </ajax:AutoCompleteExtender>  

    </div>  

    </form>  

    </body>  

    </html>  

    Aspx.cs  

    Codding  

    using System.Data;  

    using System.Data.SqlClient;  

    using System.Collections.Generic;  

    using System.Configuration;  

      
      

    [System.Web.Script.Services.ScriptMethod()]  

    [System.Web.Services.WebMethod]  

    public static List<string> GetCountries(string prefixText)  

    {  

    SqlConnection con = newSqlConnection(ConfigurationManager.ConnectionStrings["dbconnection"].ToString());  

    con.Open();  

    SqlCommand cmd = new SqlCommand("select * from Country where CountryName like @Name+'%'", con);  

    cmd.Parameters.AddWithValue("@Name", prefixText);  

    SqlDataAdapter da = new SqlDataAdapter(cmd);  

    DataTable dt = new DataTable();  

    da.Fill(dt);  

    List<string> CountryNames = new List<string>();  

    for (int i = 0; i < dt.Rows.Count; i++)  

    {  

    CountryNames.Add(dt.Rows[i][1].ToString());  

    }  

    return CountryNames;  

    }  

    0