Вопрос

I have a ASP.NEt Application with a Ajax AutoComplete Extender and it works fine but I want only see 10 to 15 elements in the List. How I can I do it?

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>

My cs code:

[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));
}
Это было полезно?

Решение

Load Linq namespaces and use Take method

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

Другие советы

Can you try

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

This will give exactly 10 elements.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top