Click here to Skip to main content
15,886,724 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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


XML
<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
XML
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

 
Share this answer
 
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.


XML
<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();
		}
	}

}
 
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