如何设置十个元素的AutoCompleteList?

时间:2012-09-14 08:33:37

标签: c# asp.net ajax autocomplete autocompleteextender

我有一个带有Ajax AutoComplete Extender的ASP.NEt应用程序,它工作正常,但我只希望在List中看到10到15个元素。我怎么能这样做?

ASPX:

<asp:TextBox ID="txtVertreter" runat="server"></asp:TextBox>
                                <asp:AutoCompleteExtender ID="AutoComlete" runat="server" TargetControlID="txtVertreter" 
                                ServiceMethod="GetCompletionList" ServicePath="" Enabled="true"
                                DelimiterCharacters="" UseContextKey="true" MinimumPrefixLength="1" ></asp:AutoCompleteExtender>

我的cs代码:

[System.Web.Script.Services.ScriptMethod]
[System.Web.Services.WebMethod]
public static string[] GetCompletionList(string prefixText, int count)
{
    ArrayList filteredList = new ArrayList();
    string s2 = "\n";
    char[] ch = s2.ToCharArray();

    UserService srv = new UserService();
    ArrayList AList = srv.VertreterFinden(Domain, prefixText);

    string[] names = AList.ToArray(typeof(string)) as string[];

    foreach (string name in names)
    {
        if
          (name.ToLower().StartsWith(prefixText.ToLower()))
        {
            filteredList.Add(name);
        }
    } return (string[])
        filteredList.ToArray(typeof(string));
}

2 个答案:

答案 0 :(得分:2)

加载Linq命名空间并使用Take方法

filteredList.Take(10).ToArray(typeof(string));

答案 1 :(得分:1)

你能试试吗

return (string[])
        filteredList.Take(10).ToArray(typeof(string));

这将给出10个元素。