C# AjaxControlToolKit AutoCompleteXtender未呈现
我正在使用Asp.Net/C,在我的一个页面中,我正在使用Ajax AutoCompleteXtender进行自动建议,下面是我正在使用的代码C# AjaxControlToolKit AutoCompleteXtender未呈现,c#,asp.net,ajaxcontroltoolkit,C#,Asp.net,Ajaxcontroltoolkit,我正在使用Asp.Net/C,在我的一个页面中,我正在使用Ajax AutoCompleteXtender进行自动建议,下面是我正在使用的代码 <Services> <asp:ServiceReference Path="AutoCompleteSearchByName.asmx" /> </Services> </asp:ScriptManager> <as
<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" />
这是我的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;
}
}
}
谁能建议我如何解决这个问题。
谢谢检查您是否为此使用了正确的DLL,并查看下面的代码 如果仍然不起作用,请检查本文,并通过编写代码检查您犯了什么错误: 试试这个:
<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,这是本文的全文:我尝试了您发布的代码,现在它说错误创建控件autocomplete1“true”无法在属性“caching”上设置。我建议您下载该文章的代码,然后尝试将其包含在项目中,或者通过比较代码来检查错误。我不确定您是否使用AutocompleteSearchByName.asmx。如果是这样,那一定是出了什么问题。你能显示一下你的自动完成搜索名asmx的代码吗?@AshwiniVerma,我编辑了我的question@freebird:您正在使用ScriptManager吗?尝试使用ToolkitScriptManager而不是ScriptManager。
<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">