提示输入信息将根据与 AutoComplete 配合的 Web Service 来提供,并显示于 TextBox 的左下方。
在上面的例子中,和 AutoComplete 所配合的 TextBox 将提示以 TextBox 中的内容为开头的输入,有点类似模拟数据库中的 Like 检索结果。 当你在 TextBox 的输入超过指定的最小长度时,提示框将显示以其输入为开头的词组和短语。
AutoComplete 控件属性将被初始化如下面的示例代码所示,斜体属性为可选属性
<ajaxToolkit:AutoCompleteExtender runat="server" ID="autoComplete1" TargetControlID="myTextBox" ServiceMethod="GetCompletionList" ServicePath="AutoComplete.asmx" MinimumPrefixLength="2" CompletionInterval="1000" EnableCaching="true" CompletionSetCount="20" CompletionListCssClass= "autocomplete_completionListElement" CompletionListItemCssClass= "autocomplete_listItem" CompletionListHighlightedItemCssClass= "autocomplete_highlightedListItem" DelimiterCharacters=";, :"> <Animations> <OnShow> ... </OnShow> <OnHide> ... </OnHide> </Animations> </ajaxToolkit:AutoCompleteExtender>
1、TargetControlID:指定要实现提示功能的控件。 2、ServicePath:WebService的路径,提取数据的方法是写在一个WebService中的。 3、ServeiceMethod:写在WebService中的用于提取数据的方法的名字。 4、MinimumPrefixLength:用来设置用户输入多少字母才出现提示效果。 5、CompletionSetCount:设置提示数据的行数。 6、CompletionInterval:从服务器获取书的时间间隔,单位是毫秒。
WebService示例代码:
注意:
你可以根据你的需要任意替换方法名“GetCompletionList”,但是返回值和参数必须保持一致
[System.Web.Services.WebMethod]
[System.Web.Script.Services.ScriptMethod]
public string[] GetCompletionList(
string prefixText, int count,
string contextKey) { ... }
注意:
你可以根据你的需要任意替换方法名“GetCompletionList”,但是返回值和参数必须保持一致
- OnShow - 当显示提示信息的时候出现的动画。动画可以应用 <HideAction Visible="true" />来控制显示提示框的其可视化信息。
- OnHide - 当提示信息框被关闭时出现的动画