简介
AutoComplete控件就是在用户在文本框输入前几个字母或是汉字的时候,该控件就能从存放数据的文或是数据库里将所有以这些字母开头的数据提示给用户,供用户选择,提供方便。
重要属性
1.TargetControlID:指定要实现提示功能的控件;
2.ServicePath:WebService的路径,提取数据的方法是写在一个WebService中的;
3.ServeiceMethod:写在WebService中的用于提取数据的方法的名字;
4.MinimumPrefixLength:用来设置用户输入多少字母才出现提示效果;
5.CompletionSetCount:设置提示数据的行数;
6.CompletionInterval:从服务器获取书的时间间隔,单位是毫秒。
新建一个webservices文件,输入代码:
![InBlock.gif](p_w_picpaths/editer/InBlock.gif)
![InBlock.gif](p_w_picpaths/editer/InBlock.gif)
![InBlock.gif](p_w_picpaths/editer/InBlock.gif)
![InBlock.gif](p_w_picpaths/editer/InBlock.gif)
![InBlock.gif](p_w_picpaths/editer/InBlock.gif)
![InBlock.gif](p_w_picpaths/editer/InBlock.gif)
![InBlock.gif](p_w_picpaths/editer/InBlock.gif)
/// <summary>
/// AutoComplete 的摘要说明
/// <summary>
![InBlock.gif](p_w_picpaths/editer/InBlock.gif)
![InBlock.gif](p_w_picpaths/editer/InBlock.gif)
![InBlock.gif](p_w_picpaths/editer/InBlock.gif)
![InBlock.gif](p_w_picpaths/editer/InBlock.gif)
![InBlock.gif](p_w_picpaths/editer/InBlock.gif)
![InBlock.gif](p_w_picpaths/editer/InBlock.gif)
![InBlock.gif](p_w_picpaths/editer/InBlock.gif)
![InBlock.gif](p_w_picpaths/editer/InBlock.gif)
![InBlock.gif](p_w_picpaths/editer/InBlock.gif)
![InBlock.gif](p_w_picpaths/editer/InBlock.gif)
![InBlock.gif](p_w_picpaths/editer/InBlock.gif)
![InBlock.gif](p_w_picpaths/editer/InBlock.gif)
![InBlock.gif](p_w_picpaths/editer/InBlock.gif)
![InBlock.gif](p_w_picpaths/editer/InBlock.gif)
![InBlock.gif](p_w_picpaths/editer/InBlock.gif)
![InBlock.gif](p_w_picpaths/editer/InBlock.gif)
![InBlock.gif](p_w_picpaths/editer/InBlock.gif)
![InBlock.gif](p_w_picpaths/editer/InBlock.gif)
return responses.ToArray();
![InBlock.gif](p_w_picpaths/editer/InBlock.gif)
![InBlock.gif](p_w_picpaths/editer/InBlock.gif)
在aspx文件中拖入一个文本框和一个AutoCompleteExtender控件,aspx源码如下
<%@ Page Language=
"C#" AutoEventWireup=
"true" CodeFile=
"Default.aspx.cs"
Inherits=
"_Default" %>
<%@ Register assembly= "AjaxControlToolkit" namespace= "AjaxControlToolkit" tagprefix= "asp" %>
<%@ Register assembly= "System.Web.Ajax" namespace= "System.Web.UI" tagprefix= "asp" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns= "http://www.w3.org/1999/xhtml">
<head runat= "server">
<title></title>
</head>
<body>
<form id= "form1" runat= "server">
<div>
<asp:AjaxScriptManager ID= "AjaxScriptManager1" runat= "server">
</asp:AjaxScriptManager>
<asp:TextBox ID= "TextBox1" runat= "server" ></asp:TextBox>
<asp:AutoCompleteExtender
ID= "AutoCompleteExtender1"
runat= "server"
ServicePath= "WebService.asmx"
ServiceMethod= "GetSuggestions"
TargetControlID= "TextBox1"
MinimumPrefixLength= "2"
CompletionSetCount= "10"
CompletionInterval= "100">
</asp:AutoCompleteExtender>
</div>
</form>
</body>
</html>
<%@ Register assembly= "AjaxControlToolkit" namespace= "AjaxControlToolkit" tagprefix= "asp" %>
<%@ Register assembly= "System.Web.Ajax" namespace= "System.Web.UI" tagprefix= "asp" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns= "http://www.w3.org/1999/xhtml">
<head runat= "server">
<title></title>
</head>
<body>
<form id= "form1" runat= "server">
<div>
<asp:AjaxScriptManager ID= "AjaxScriptManager1" runat= "server">
</asp:AjaxScriptManager>
<asp:TextBox ID= "TextBox1" runat= "server" ></asp:TextBox>
<asp:AutoCompleteExtender
ID= "AutoCompleteExtender1"
runat= "server"
ServicePath= "WebService.asmx"
ServiceMethod= "GetSuggestions"
TargetControlID= "TextBox1"
MinimumPrefixLength= "2"
CompletionSetCount= "10"
CompletionInterval= "100">
</asp:AutoCompleteExtender>
</div>
</form>
</body>
</html>
![InBlock.gif](p_w_picpaths/editer/InBlock.gif)
![InBlock.gif](p_w_picpaths/editer/InBlock.gif)
![InBlock.gif](p_w_picpaths/editer/InBlock.gif)
![InBlock.gif](p_w_picpaths/editer/InBlock.gif)
![InBlock.gif](p_w_picpaths/editer/InBlock.gif)
![InBlock.gif](p_w_picpaths/editer/InBlock.gif)
![InBlock.gif](p_w_picpaths/editer/InBlock.gif)
public partial class _Default : System.Web.UI.Page
![InBlock.gif](p_w_picpaths/editer/InBlock.gif)
![InBlock.gif](p_w_picpaths/editer/InBlock.gif)
![InBlock.gif](p_w_picpaths/editer/InBlock.gif)
![InBlock.gif](p_w_picpaths/editer/InBlock.gif)
}
![InBlock.gif](p_w_picpaths/editer/InBlock.gif)
转载于:https://blog.51cto.com/visionsky/268650