【发布时间】:2012-03-24 17:28:33
【问题描述】:
我想在 TextBox 中使用 AutoCompleteExtender 进行自动完成。但没有得到结果。我使用了以下语法: 在 aspx 页面中::
<asp:scriptmanager EnablePageMethods="true" runat="server"></asp:scriptmanager>
<asp:TextBox ID="txtautocomplete" runat="server"></asp:TextBox>
<cc1:AutoCompleteExtender ID="AutoCompleteExtender1"
Enabled="true" EnableCaching="true" MinimumPrefixLength="1"
ServiceMethod="GetNames" ServicePath="~/Autocomplete.asmx"
TargetControlID="txtautocomplete" runat="server">
</cc1:AutoCompleteExtender>
在 Autocomplete.asmx ::
[WebMethod]
[ScriptMethod()]
public static string[] GetNames(string prefixText, int count)
{
ArrayList sampleList = new ArrayList();
sampleList.Add("ABC"); sampleList.Add("Hello");
sampleList.Add("Hi"); sampleList.Add("Apple");
sampleList.Add("Hey");
ArrayList filteredList = new ArrayList();
foreach (string s in sampleList)
{
if (s.ToLower().StartsWith(prefixText.ToLower()))
filteredList.Add(s);
}
return (string[])filteredList.ToArray(typeof(string));
}
当我直接运行 Autocomplete.asmx 然后单击 Invoke 按钮时,我得到了正确的结果。我该如何解决?
【问题讨论】:
标签: c# asp.net autocomplete ajaxcontroltoolkit