0
我想在TextBox中使用AutoCompleteExtender进行自动完成。但没有得到结果。我已经使用的语法如下: 在aspx页面::AutoCompleteExtender不适用于TextBox
<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按钮我获得正确的结果。 我该如何解决它。任何帮助将不胜感激。提前致谢。
感谢@Elementenfresser我会尽快尝试。 – 2012-03-09 10:48:53