1.Demo下载:
文本框实现内容提示(仿Google、Baidu).rar
2.创建数据库、表(我用的sqlserver2008数据库)
3.创建自定义函数
4.asp.net前台页面(需要添加2个引用:AjaxControlToolkit.dll,AutoCompleteExtra.dll)
<%@ Register Assembly="AutoCompleteExtra" Namespace="AutoCompleteExtra" TagPrefix="cc1" %>
<!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>
<style type="text/css">
.searchTextBox
{
border: 1px solid #e1e1e1;
border-collapse: separate;
border-spacing: 0;
padding: 2px 2px 2px 2px;
white-space: nowrap;
margin-left: 2px;
height: 28px;
line-height: 28px;
margin-right: 5px;
font-family: 微软雅黑,宋体;
font-size: 14px;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<div>
<div class="dd2">
请输入姓名: <asp:TextBox CssClass="searchTextBox" runat="server" ID="txtCompanyName" Style="width: 280px;"></asp:TextBox>
<cc1:AutoCompleteExtraExtender ID="AutoCompleteExtraExtender1" runat="server" ServiceMethod="GetCompanyNameList"
TargetControlID="txtCompanyName" AsyncPostback="false" UseContextKey="True" AutoPostback="false"
MinimumPrefixLength="1" CompletionInterval="10">
</cc1:AutoCompleteExtraExtender>
</div>
</div>
</ContentTemplate>
</asp:UpdatePanel>
</form>
</body>
</html>
</div>
5.后台页面
namespace WebApplication1
{
public partial class TextBoxAuto : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
[System.Web.Services.WebMethodAttribute(), System.Web.Script.Services.ScriptMethodAttribute()]
public static string[][] GetCompanyNameList(string prefixText, int count, string contextKey)
{
&nbs