2008-12-28 86 views
-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(); 
     } 
    } 

AutoCompleteExtender作品有時

<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> 

這其中大部分是直接從工具包樣品的網站。除了從數據庫中填充數組外,我也完全按照示例使用Web服務來完成它。兩個都完美無瑕地填充陣列,並且有時都起作用。缺乏表現力,他們似乎是相同的。

我在另一個頁面上使用了幾個日曆控件,他們的工作完美無瑕,但浪費太多時間試圖使這項工作始終如一。

+2

什麼問題? – 2008-12-28 23:55:32

回答

1

我發現如果服務器端代碼需要很長時間才能執行,客戶端AJAX請求似乎超時。

我沒有試圖證明這一點,因爲當我只調整服務器端代碼以提高性能時,這些努力似乎更值得。

檢查你的數據集是否被緩存,如果沒有,檢索它需要多長時間?檢查數據庫索引。 Sql LIKE查詢在SQL Server 2005中得到了更好的優化。

如果它不是超時並且實際上是服務器端錯誤,則可以通過瀏覽器訪問它並在本地測試web服務,然後鍵入您將使用的查詢在「自動完成」文本框中。或者,在沒有結果並查找ASP.NET警告事件之後,檢查服務器事件日誌。