1

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));
}
4

2 に答える 2

2

Linq 名前空間を読み込み、Take メソッドを使用する

filteredList.Take(10).ToArray(typeof(string));
于 2012-09-14T08:35:51.657 に答える
1

試してみませんか

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

これにより、ちょうど 10 個の要素が得られます。

于 2012-09-14T08:41:21.147 に答える