我正在使用Asp.Net/C#
,在我的某个页面中,我使用Ajax autocompleteextender
作为自动建议,以下是我正在使用的代码
<Services>
<asp:ServiceReference Path="AutoCompleteSearchByName.asmx" />
</Services>
</asp:ScriptManager>
<asp:TextBox ID="txtCountry" runat="server"></asp:TextBox>
<ajaxtoolkit:autocompleteextender runat="server" ID="autoComplete1"
TargetControlID="txtCountry" ServicePath="AutoCompleteSearchByName.asmx"
ServiceMethod="GetNames" MinimumPrefixLength="1" EnableCaching="true" />
但是在设计模式下它给了我一个错误。错误说,
Error creating control autocomplete1 , AutocompleteSearchByName.asmx could not be set on property ServicePath
这是我的AutoCompleteSearchByName.asmx代码
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
namespace CwizBankApp
{
/// <summary>
/// Summary description for AutoCompleteSearchByName
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
//[System.Web.Script.Services.ScriptService]
public class AutoCompleteSearchByName : System.Web.Services.WebService
{
[WebMethod]
public string[] GetNames(string prefixText)
{
DataSet dst = new DataSet();
SqlConnection sqlCon = new SqlConnection(ConfigurationManager.AppSettings["Server=Server;Database=CwizData;Trusted_Connection=True"]);
string strSql = "SELECT f_name FROM cust_master WHERE f_name LIKE '" + prefixText + "%' ";
SqlCommand sqlComd = new SqlCommand(strSql, sqlCon);
sqlCon.Open();
SqlDataAdapter sqlAdpt = new SqlDataAdapter();
sqlAdpt.SelectCommand = sqlComd;
sqlAdpt.Fill(dst);
string[] cntName = new string[dst.Tables[0].Rows.Count];
int i = 0;
try
{
foreach (DataRow rdr in dst.Tables[0].Rows)
{
cntName.SetValue(rdr["f_name"].ToString(), i);
i++;
}
}
catch { }
finally
{
sqlCon.Close();
}
return cntName;
}
}
}
有人可以建议我如何解决这个问题。 感谢
答案 0 :(得分:1)
检查您是否正在使用适当的DLL,并查看以下代码aslo
如果它仍然不起作用,请查看本文并通过代码检查您所犯的错误:AutoComplete With DataBase and AjaxControlToolkit
试试这个:
<ajaxToolkit:ToolkitScriptManager ID="ScriptManager1" runat="server">
</ajaxToolkit:ToolkitScriptManager>
<ajaxToolkit:AutoCompleteExtender ID="autoComplete1" runat="server"
EnableCaching="true"
BehaviorID="AutoCompleteEx"
MinimumPrefixLength="2"
TargetControlID="myTextBox"
ServicePath="AutoComplete.asmx"
ServiceMethod="GetCompletionList"
CompletionInterval="1000"
CompletionSetCount="20"
CompletionListCssClass="autocomplete_completionListElement"
CompletionListItemCssClass="autocomplete_listItem"
CompletionListHighlightedItemCssClass="autocomplete_highlightedListItem"
DelimiterCharacters=";, :"
ShowOnlyCurrentWordInCompletionListItem="true">
或
这不符合你的回答,但如果你想要你也可以去jquery soltuion这里是完整的文章:Cascading with jQuery AutoComplete