[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 服务完成了它。两者都完美地填充了数组,并且有时都可以工作。缺乏性能方面,它们似乎是相同的。
我在另一个页面上使用了几个日历控件,它们完美地工作,但浪费了太多时间试图使这项工作始终如一。