Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/75.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何在单个文本框中多次使用autocomplete extender?_C#_Jquery_Asp.net_Autocomplete - Fatal编程技术网

C# 如何在单个文本框中多次使用autocomplete extender?

C# 如何在单个文本框中多次使用autocomplete extender?,c#,jquery,asp.net,autocomplete,C#,Jquery,Asp.net,Autocomplete,我正在ASP.NET中开发一个基于房地产的应用程序。这里,我想 使用自动完成扩展程序获取城市。我试过以下方法 下面是设计部分,我使用了名为“txtCity”的文本框,以及目标控件为“txtCity”的自动完成扩展器和 web服务方法是“GetCities” 无Webservice的Ajax AutoCompleteXtender 下面是Webservice方法,它将以列表的形式返回城市名称 using System.Data; using System.Data.SqlClient; usi

我正在ASP.NET中开发一个基于房地产的应用程序。这里,我想 使用自动完成扩展程序获取城市。我试过以下方法

下面是设计部分,我使用了名为“txtCity”的
文本框
,以及目标控件为“txtCity”的自动完成扩展器和 web服务方法是“GetCities”


无Webservice的Ajax AutoCompleteXtender
下面是Webservice方法,它将以列表的形式返回城市名称

using System.Data;
using System.Data.SqlClient;
using System.Collections.Generic;
using System.Configuration;


[System.Web.Services.WebMethod]
public static List<string> GetCities(string prefixText)
{
   SqlConnection con = new SqlConnection  
  (ConfigurationManager.ConnectionStrings["dbconnection"].ToString());
  con.Open();
  SqlCommand cmd = new SqlCommand("select * from City where CityName  
  like @Name+'%'", con);
  cmd.Parameters.AddWithValue("@Name", prefixText);
  SqlDataAdapter da = new SqlDataAdapter(cmd);
  DataTable dt = new DataTable();
  da.Fill(dt);
  List<string> CoityNames = new List<string>();
  for (int i = 0; i < dt.Rows.Count; i++)
  {
     CityNames.Add(dt.Rows[i][1].ToString());
  }
  return CityNames;

}
使用系统数据;
使用System.Data.SqlClient;
使用System.Collections.Generic;
使用系统配置;
[System.Web.Services.WebMethod]
公共静态列表GetCities(字符串前缀)
{
SqlConnection con=新的SqlConnection
(ConfigurationManager.ConnectionString[“dbconnection”].ToString());
con.Open();
SqlCommand cmd=new SqlCommand(“从CityName所在的城市选择*)
例如@Name+“%”,con);
cmd.Parameters.AddWithValue(“@Name”,prefixText);
SqlDataAdapter da=新的SqlDataAdapter(cmd);
DataTable dt=新的DataTable();
da.填充(dt);
List COITYNAME=新列表();
对于(int i=0;i
在这里,当我输入任何字符时,所有与该字符匹配的城市将以下拉方式显示,选择任何城市后,所选城市将显示在文本框中

当我搜索另一个城市时,新城市会出现在文本框中,而以前选择的城市会被删除。但我不希望以前选定的城市消失


我想使用99acres.com等网站中使用的功能。

这里正在使用RAD控件演示确切的功能

您只需要设置SQL数据源和一些AJAX包装

截图:

您可以使用Jquery插件来实现这一点。我认为没有任何方法可以自定义这些服务器控件。只要使用这些控件提供的功能,它们就很好。Jquery控件为您提供了根据需要进行协同细分的可能性。这就是为什么有这么多jquery控件可用,如果不可用,您可以轻松构建自己的控件。我已经通过适当的缩进(因为它提高了可读性)对代码进行了更好的格式化并且还删除了设计和web服务代码之间文本的额外缩进,因为否则它会隐藏在代码块中。为了更好地解释你的问题,我还改写了这些句子。请不要对普通文本使用代码块格式(缩进4个字符)。如果要突出显示某些文本,请使用粗体、斜体等文本格式选项。此外,标题中通常不需要语言名称,因为它们是标记的一部分。
using System.Data;
using System.Data.SqlClient;
using System.Collections.Generic;
using System.Configuration;


[System.Web.Services.WebMethod]
public static List<string> GetCities(string prefixText)
{
   SqlConnection con = new SqlConnection  
  (ConfigurationManager.ConnectionStrings["dbconnection"].ToString());
  con.Open();
  SqlCommand cmd = new SqlCommand("select * from City where CityName  
  like @Name+'%'", con);
  cmd.Parameters.AddWithValue("@Name", prefixText);
  SqlDataAdapter da = new SqlDataAdapter(cmd);
  DataTable dt = new DataTable();
  da.Fill(dt);
  List<string> CoityNames = new List<string>();
  for (int i = 0; i < dt.Rows.Count; i++)
  {
     CityNames.Add(dt.Rows[i][1].ToString());
  }
  return CityNames;

}