我有一个带有Ajax AutoComplete扩展器的ASP.NEt应用程序,它工作得很好,但我只想在列表中看到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));
}发布于 2012-09-14 16:35:52
加载Linq命名空间并使用Take方法
filteredList.Take(10).ToArray(typeof(string));发布于 2012-09-14 16:41:21
你能试一下吗?
return (string[])
filteredList.Take(10).ToArray(typeof(string));这将恰好给出10个元素。
https://stackoverflow.com/questions/12420790
复制相似问题