1

I am Very much new to C Sharp. In My project I am designing a search page where I have Text Box with AJAX Control Auto Extender, I am Using a Web Service to fill the Text Box (This is the first time I am Using Web Service I don’t know to what the Web Service will be used) when the User Types the Word in the Text Box. I had specified everything correctly, when I run my Program and type the Word there is no response.

This Question may look like a Duplicate Question but not I had googled out many time seen many blogs worked out with the Examples shown there but No Result. Somebody help me please,

My Web Service Code is,

    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];
          }
       }

    } 
  }

My AJAX Tool Script Manager is

   <asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
    <Services>
        <asp:ServiceReference Path="~/Search.asmx" />
    </Services>
</asp:ToolkitScriptManager>

My Text Box and Auto Complete Extender is,

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

1 回答 1

-1

发生这种情况是因为在文件后面的代码中为GetCompletionList(string prefixText, int count)您使用了两个参数,而在 .aspx 页面中您正在调用此方法而没有参数,就像简单地一样ServiceMethod="GetCompletionList"。如果您从GetCompletionList()代码中删除参数将起作用。

我知道你需要参数string prefixText。该变量prefixText只不过是在文本框中输入的值,用于从数据库中获取数据,以便相应地为您提供数据。因此,不要在查询中使用此参数值,只需使用文本框值,如select * from table where name like '%textbox.Text%'

于 2013-09-29T16:04:59.980 回答