我在asp.net上有一个网络表单和一个文本框和一个按钮来搜索网站上的数据我想在我的文本框上实现一个自动完成属性它运行得很完美但是没有显示我已经给出2个长度的前缀我有在我的项目中添加了ajax工具包,请帮助我完成它, 在我的 WEB FORM 1.aspx
上<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="ESEPAK.WebForm1" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<link href="css/bootstrap.css" rel="stylesheet" />
<link href="css/bootstrap.min.css" rel="stylesheet" />
<%-- <link href="css/bootstrapAmelia.css" rel="stylesheet" />
<link href="css/bootstrapAmelia.min.css" rel="stylesheet" />--%>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:AutoCompleteExtender ID="AutoCompleteExtender1" runat="server"
ServiceMethod="AutoCompleteAjaxRequest"
ServicePath="AutoComplete.asmx"
MinimumPrefixLength="2"
CompletionInterval="100"
EnableCaching="false"
CompletionSetCount="10"
TargetControlID="TextBox1"
FirstRowSelected="false">
</asp:AutoCompleteExtender>
</div>
<asp:UpdatePanel ID="UpdatePanel1" runat="server"></asp:UpdatePanel>
在我的 Web Form1.aspx.cs
上namespace ESEPAK
{
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
[System.Web.Script.Services.ScriptService]
public partial class WebForm1 : System.Web.UI.Page
{
Database _db = DatabaseFactory.CreateDatabase();
DataSet ds = new DataSet();
SqlConnection Conn = new SqlConnection(ConfigurationManager.ConnectionStrings["DBCS"].ConnectionString);
protected void Page_Load(object sender, EventArgs e)
{
}
public class AutoComplete : System.Web.Services.WebService
{
[WebMethod]
public string[] AutoCompleteAjaxRequest(string prefixText, int count)
{
List<string> ajaxDataCollection = new List<string>();
DataTable dt = new DataTable();
dt = getdata(prefixText);
if (dt.Rows.Count > 0)
{
for (int i = 0; i < dt.Rows.Count; i++)
{
ajaxDataCollection.Add(dt.Rows[i]["Name"].ToString());
}
}
return ajaxDataCollection.ToArray();
}
public DataTable getdata(string prefixText)
{
SqlConnection Conn = new SqlConnection(ConfigurationManager.ConnectionStrings["DBCS"].ConnectionString);
string query = "select * from SHOPHIVECAT";
SqlDataAdapter sda = new SqlDataAdapter(query, Conn);
DataTable dt = new DataTable();
sda.Fill(dt);
return dt;
}
}}}