自动完成扩展器的问题 [英] problem with autocomplete extender

查看:50
本文介绍了自动完成扩展器的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<asp:TextBox ID="txtCountry" runat="server"></asp:TextBox>
<ajax:AutoCompleteExtender ID="AutoCompleteExtender1" runat="server" TargetControlID="txtCountry" ServicePath="Service.asmx"

MinimumPrefixLength="2" EnableCaching="true" CompletionSetCount="2" ServiceMethod="GetCountries" OnClientPopulating="ShowProcessImage" OnClientPopulated="HideProcessImage" >
</ajax:AutoCompleteExtender>




services.cs
............




services.cs
............

[WebMethod]
  public List<string> GetCountries(string prefixText)
  {
      SqlConnection con = new SqlConnection("Data Source=112.118.11.11;Database=rmt;uid=migration;password=g#2007");
      con.Open();
      SqlCommand cmd = new SqlCommand("select * from Countries where Cname like @Name+'%'", con);
      cmd.Parameters.AddWithValue("@Name", prefixText);
      SqlDataAdapter da = new SqlDataAdapter(cmd);
      DataTable dt = new DataTable();
      da.Fill(dt);
      List<string> CountryNames = new List<string>();
      for (int i = 0; i < dt.Rows.Count; i++)

      {

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

      }

      return CountryNames;

  }









finally popup not displayed specific character in a textbox.

推荐答案

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

MinimumPrefixLength="1" EnableCaching="true" CompletionSetCount="1" CompletionInterval="1000" ServiceMethod="GetCountries" >
</ajax:AutoCompleteExtender>



services.cs



services.cs

[System.Web.Script.Services.ScriptMethod()]
[System.Web.Services.WebMethod]
public static List<string> GetCountries(string prefixText)
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["dbconnection"].ToString());
con.Open();
SqlCommand cmd = new SqlCommand("select * from Country where CountryName like @Name+'%'", con);
cmd.Parameters.AddWithValue("@Name", prefixText);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
da.Fill(dt);
List<string> CountryNames = new List<string>();
for (int i = 0; i < dt.Rows.Count; i++)

{

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

}

return CountryNames;

}



web.Config



web.Config

<connectionStrings>
<add name="dbconnection" connectionString="Data Source=112.118.11.11;uid=migration;password=g#2007;Initial Catalog=rmt"/>
</connectionStrings >


这篇关于自动完成扩展器的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆