Quantcast
Channel: ASP.NET AJAX + Ajax Control Toolkit (ACT)
Viewing all articles
Browse latest Browse all 5678

auto complete ajax control does not work?

$
0
0

Hlo Sir

Auto complete control does not work properly when i input some character it does not show that word that comes from database.

Here is my code.

Please execute it.

Aspx<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm48.aspx.cs" Inherits="WebApplication14.WebForm48" %><html xmlns="http://www.w3.org/1999/xhtml"><head runat="server"><title></title></head><body><form id="form1" runat="server"><div><asp:TextBox ID="txtCity" runat="server"></asp:TextBox><ajaxToolkit:AutoCompleteExtender ID="AutoCompleteExtender1" runat="server" TargetControlID="txtCity"
MinimumPrefixLength="1" EnableCaching="true" CompletionSetCount="1" CompletionInterval="1000" ServiceMethod="GetCity" ></ajaxToolkit:AutoCompleteExtender></div></form></body></html>

C#

using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Data;

using System.Data.SqlClient;

using System.Configuration;

namespace WebApplication14
{

    public partial class WebForm48 : System.Web.UI.Page
    {
        

        
      
  protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {

            }
        }

      

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

        [System.Web.Services.WebMethod]

        public static List<string> GetCity(string prefixText)

        {

            DataTable dt = new DataTable();

            string constr = ConfigurationManager.AppSettings["con"].ToString();

            SqlConnection con = new SqlConnection(constr);

            con.Open();

            SqlCommand cmd = new SqlCommand("select * from City where CityName like @City+'%'", con);

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

            SqlDataAdapter adp = new SqlDataAdapter(cmd);

            adp.Fill(dt);

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

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

            {

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

            }

            return CityNames;

        }
    }
}


 


Viewing all articles
Browse latest Browse all 5678

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>