-4
    [System.Web.Services.WebMethod]
    [System.Web.Script.Services.ScriptMethod]
    public string[] GetRowsByFilter(string prefixText, int count)
    //public static List<string> GetRowsByFilter(string prefixText)
    {
        DataTable table = ds.Tables[0];
        string filter = "stShortName LIKE '" + prefixText.Replace("'", "''") + "%'";
        DataRow[] foundRows;
        List<string> items = new List<string>(count);

        foundRows = table.Select(filter);
        if (foundRows.Length > 0)
        {
             for (int i = 0; i < foundRows.Length; i++)
            {
                items.Add((string)foundRows[i]["stShortName"]);
            }
            return items.ToArray();
        }
        else
        {
            items.Add("No '" + prefixText + "' items found");
            return items.ToArray();
        }
    }

<ajaxToolkit:AutoCompleteExtender 
    id="AutoCompleteExtenderTxtSite" 
    BehaviorID="AutoCompleteEx"
    Runat="server" 
    Targetcontrolid="txtSiteASP"
    ServiceMethod="GetRowsByFilter"
    MinimumPrefixLength="1" 
    CompletionInterval="1000"
    EnableCaching="false"
    CompletionSetCount="10" 
    CompletionListCssClass="autocomplete_completionListElement" 
    CompletionListItemCssClass="autocomplete_listItem" 
    CompletionListHighlightedItemCssClass="autocomplete_highlightedListItem"
    DelimiterCharacters=";, :"
    ShowOnlyCurrentWordInCompletionListItem="true" 
  >
    <Animations>
        <OnShow>
            <Sequence>
                <OpacityAction Opacity="0" />
                <HideAction Visible="true" />
                <ScriptAction Script="
                    // Cache the size and setup the initial size
                    var behavior = $find('AutoCompleteEx');
                    if (!behavior._height) {
                        var target = behavior.get_completionList();
                        behavior._height = target.offsetHeight - 2;
                        target.style.height = '0px';
                    }" />
                <Parallel Duration=".4">
                    <FadeIn />
                    <Length PropertyKey="height" StartValue="0" EndValueScript="$find('AutoCompleteEx')._height" />
                </Parallel>
            </Sequence>
        </OnShow>
        <OnHide>
            <Parallel Duration=".4">
                <FadeOut />
                <Length PropertyKey="height" StartValueScript="$find('AutoCompleteEx')._height" EndValue="0" />
            </Parallel>
        </OnHide>
    </Animations>
</ajaxToolkit:AutoCompleteExtender>

其中大部分内容直接来自 Toolkit 示例网站。除了从数据库中填充数组外,我也完全按照示例中的方式使用 Web 服务完成了它。两者都完美地填充了数组,并且有时都可以工作。缺乏性能方面,它们似乎是相同的。

我在另一个页面上使用了几个日历控件,它们完美地工作,但浪费了太多时间试图使这项工作始终如一。

4

1 回答 1

1

我发现如果服务器端代码需要很长时间才能执行,客户端 AJAX 请求似乎会超时。

我没有试图证明这一点,因为当我可以调整服务器端代码以提高性能时,这种努力似乎非常值得。

检查您的数据集是否被缓存,如果没有,检索它需要多长时间?检查数据库索引。Sql LIKE 查询在 SQL Server 2005 中得到了更好的优化。

如果它不是超时并且实际上是服务器端错误,请通过浏览器访问它并在“自动完成”文本框中键入您将使用的查询来在本地测试 Web 服务。或者,在没有结果后检查服务器事件日志并查找 ASP.NET 警告事件。

于 2009-03-11T11:11:42.577 回答