Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: .NET4 ASP:NET
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"
                MinimumPrefixLength="1"
                EnableCaching="true"
                CompletionInterval="100"
                ServiceMethod="GetSuggessions"
                CompletionSetCount="20"
                ContextKey="strOtherPram">
                </ajax:AutoCompleteExtender>
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)
                  .ToList<tblCity>();
 
          }
 
          return result;
      }
I am not able to bind data to textbox
Posted 19-Mar-13 0:34am
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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

Solution 2

Hi,
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">
                   </cc1:AutoCompleteExtender>
 

 
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 = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.Web.Script.Services.ScriptService()]
public class AutoFileNew : System.Web.Services.WebService
{
 
	[WebMethod()]
	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()) {
				titleArList.Add(dr["file_number"].ToString());
			}
			return titleArList.ToArray();
 
		} catch (Exception ex) {
		} finally {
			Myapplication.mConn.Close();
		}
	}
 
}
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 230
1 PIEBALDconsult 150
2 DamithSL 125
3 BillWoodruff 108
4 Garth J Lancaster 90
0 OriginalGriff 5,790
1 DamithSL 4,601
2 Maciej Los 4,012
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,195


Advertise | Privacy | Mobile
Web04 | 2.8.141220.1 | Last Updated 19 Mar 2013
Copyright © CodeProject, 1999-2014
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