Click here to Skip to main content
13,047,502 members (63,164 online)
Rate this:
Please Sign up or sign in to vote.
See more:
Hi EveryBody,

In My Application i want to bind City data to textbox using auto complete Using AJAX toolkit. I am added below source code in my page

<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
                <ajax:AutoCompleteExtender ID="AutoCompleteExtender1" runat="server" TargetControlID="TextBox1"

below is my code where i am retrive city and store in list which is store in Master Class
public static List<tblCity> GetCities(long StateId)
          List<tblCity> result = null;
          using (var context = new HealthEntities())
              result = context.tblCities
                  .Where(c => c.StateId == StateId)
          return result;

I am not able to bind data to textbox
Posted 18-Mar-13 23:34pm
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Rate this: bad
Please Sign up or sign in to vote.

Solution 2

You can call a method thro a service. Add ServicePath in your html. Create a service and call your method. In my code, the method gets data via Stored Proc, which you can eliminate.

<cc1:AutoCompleteExtender ID="AutoCompleteExtender2" runat="server" CompletionInterval="1000"
                       CompletionSetCount="12" EnableCaching="true" MinimumPrefixLength="1" ServiceMethod="FindFileNumberMT"
                       Enabled="true" ServicePath="../AutoFileNew.asmx" TargetControlID="txtFileNumber">

using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Data.SqlClient;
using System.Data.Common;
[WebService(Namespace = "")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class AutoFileNew : System.Web.Services.WebService
	public string[] FindFileNumberMT(string prefixText, int count)
		List<string> titleArList = new List<string>();
		SqlDataReader dr = null;
		SqlCommand oCmd = new SqlCommand("sp_GetAutoFileNumbersNew",Myapplication.mConn);
		oCmd.CommandType = CommandType.StoredProcedure;
		oCmd.Parameters.Add("@filenumber", SqlDbType.VarChar, 50).Value = prefixText;
		try {
			dr = oCmd.ExecuteReader();
			while (dr.Read()) {
			return titleArList.ToArray();
		} catch (Exception ex) {
		} finally {

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170713.1 | Last Updated 19 Mar 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100