C# 带有Web服务的AJAX自动完成扩展器

C# 带有Web服务的AJAX自动完成扩展器,c#,asp.net,ajax,C#,Asp.net,Ajax,我对C夏普非常陌生。在我的项目中,我正在设计一个搜索页面,其中有一个带有AJAX控件Auto Extender的文本框,我正在使用Web服务填充文本框。这是我第一次使用Web服务,我不知道当用户在文本框中键入单词时,将使用什么Web服务。我已经正确地指定了所有内容,当我运行程序并键入单词there'snooresponse时 这个问题可能看起来像一个重复的问题,但不是。我曾在谷歌上搜索过很多次,看到很多博客都用上面的例子解决了这个问题,但没有结果。谁来帮帮我 我的Web服务代码是 usi

我对C夏普非常陌生。在我的项目中,我正在设计一个搜索页面,其中有一个带有AJAX控件Auto Extender的文本框,我正在使用Web服务填充文本框。这是我第一次使用Web服务,我不知道当用户在文本框中键入单词时,将使用什么Web服务。我已经正确地指定了所有内容,当我运行程序并键入单词there'snooresponse时

这个问题可能看起来像一个重复的问题,但不是。我曾在谷歌上搜索过很多次,看到很多博客都用上面的例子解决了这个问题,但没有结果。谁来帮帮我

我的Web服务代码是

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.Services;
    using System.Data;
    using System.Data.SqlClient;
    using SubSonic;
    using DataAccessLayer;
    using System.Web.Configuration;

   using System.Web.Services.Protocols;
   using System.Xml.Linq;
   [WebService(Namespace = "http://tempuri.org/")]
   [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
   [System.Web.Script.Services.ScriptService]
   public class Search : System.Web.Services.WebService
   {

     public void Autocomplete()
     {


    //Uncomment the following line if using designed components
    //InitializeComponent();
     }

     [WebMethod] 
   public string[] GetCompletionList(string prefixText, int count) 
    { 
      if (count == 0) 
    { 
        count = 10; 
     } 
     DataTable dt = GetRecords(prefixText); 
    List<string> items = new List<string>(count); 

   for (int i = 0; i < dt.Rows.Count; i++) 
    { 
        string strName = dt.Rows[i][0].ToString(); 
        items.Add(strName); 
    } 
    return items.ToArray(); 
  } 

public DataTable GetRecords(string strName) 
{ 
    string QueryString;
    QueryString = System.Configuration.ConfigurationManager.ConnectionStrings     ["IUMSNXG"].ToString();
    using (SqlConnection obj_SqlConnection = new SqlConnection(QueryString))
    {
        using (SqlCommand obj_Sqlcommand = new SqlCommand())
        {
            obj_Sqlcommand.CommandType = CommandType.StoredProcedure;
            obj_Sqlcommand.CommandText = "LRS_SP_CBFM_Sel";
            obj_Sqlcommand.Connection = obj_SqlConnection;
            obj_SqlConnection.Open();

            obj_Sqlcommand.Parameters.AddWithValue("@animalCode", strName);
            SqlDataAdapter dt = new SqlDataAdapter(obj_Sqlcommand);
            DataSet ds=new DataSet();
            dt.Fill(ds);
            obj_SqlConnection.Close();
            return ds.Tables[0];
          }
       }

    } 
  }
我的AJAX工具脚本管理器是

   <asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
    <Services>
        <asp:ServiceReference Path="~/Search.asmx" />
    </Services>
</asp:ToolkitScriptManager>
我的文本框和自动完成扩展器是

 <Anthem:TextBox ID="srchtxt" runat="server" AutoUpdateAfterCallBack="true" 
                Height="19px" Width="200px"></Anthem:TextBox>
            <asp:AutoCompleteExtender ID="srchtxt_AutoCompleteExtender" runat="server" 
                CompletionInterval="100" DelimiterCharacters="" Enabled="True" 
                 ServicePath="~/Search.asmx" 
                TargetControlID="srchtxt" UseContextKey="True" 
                ServiceMethod="GetCompletionList">
            </asp:AutoCompleteExtender>

发生这种情况的原因是,在GetCompletionListstring prefixText的代码隐藏文件中,int count使用了两个参数,而在.aspx页面中,调用此方法时没有像simply ServiceMethod=GetCompletionList这样的参数。 如果从GetCompletionList中删除该参数,代码将正常工作

我知道您需要参数字符串prefixText。这个变量prefixText只不过是在textbox中输入的值,用于从数据库中获取数据,以便相应地为您提供数据。
因此,不必在查询中使用此参数值,只需使用文本框值,如select*from表格中的名称,如“%textbox.Text%”

我已使用jquery-@Deepu发布了自动完成功能。如果您不介意,Wordpress网站已被阻止。您可以在此处发布吗???您可以共享您的电子邮件地址吗。。我可以向你发送工作代码。你可以尝试此链接。你可以删除你的电子邮件id,我已经发送了。。请确认