Click here to Skip to main content
15,897,187 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I am working on a Autocomplete textbox which works fine, from
http://www.aspsnippets.com/Articles/Populate-jQuery-AutoComplete-TextBox-from-Database-using-Web-Service-in-ASPNet.aspx[^]

When the user selects any value like Kiran then it should show the result in gridview with Kiran details.The code that I have used is not working,gow do i achieve this:
C#
protected void txtSearch_TextChanged(object sender, EventArgs e)
    {
        
        string cn=ConfigurationManager.ConnectionStrings["testing"].ConnectionString;
        using(SqlConnection connection = new SqlConnection(cn))
        {    
            
           
            SqlCommand command = new SqlCommand("select * from country where EmployeeName=@EmployeeName", connection);
            command.Parameters.AddWithValue("@EmployeeName", txtSearch);
	    connection.Open();
            SqlDataReader dr = command.ExecuteReader();
            GridView1.DataSource = dr;
            GridView1.DataBind();
        }


Data Base is
SQL
insert into Country values (1,'India','Kiran')
insert into Country values (2,'India','Karan')
Posted

1 solution

TextChanged Event will not be Fire until Page is PostBack.
So, Set AutoPostBack Property of TextBox Control to TRUE.

C#
TextBox1.AutoPostBack = true;
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900