我在 aspx 页面上有一个文本框、一个脚本管理器和一个自动完成扩展器。我试图简单地在文本框中自动完成,但目前一无所获。我错过了什么?当我尝试调试代码时,断点永远不会超出 GetComplete 方法中的第一个花括号。我在VS2010
标记:
<%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"
CodeBehind="Default.aspx.cs" Inherits="AjaxAutocomplete._Default" %>
<%@ Register assembly="AjaxControlToolkit" namespace="AjaxControlToolkit" tagprefix="asp" %>
<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
</asp:Content>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:AutoCompleteExtender ID="TextBox1_AutoCompleteExtender" runat="server"
DelimiterCharacters="" Enabled="True" ServiceMethod="GetComplete" MinimumPrefixLength="3" TargetControlID="TextBox1">
</asp:AutoCompleteExtender>
</asp:Content>
后面的代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
namespace AjaxAutocomplete
{
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
[System.Web.Script.Services.ScriptMethod]
[System.Web.Services.WebMethod]
public static List<string> GetComplete(string Prefixtetxt)
{
List<string> returnList = new List<string>();
string cs = ConfigurationManager.ConnectionStrings["dbcs"].ConnectionString;
using (SqlConnection conn = new SqlConnection(cs))
{
conn.Open();
using (SqlCommand cmd = new SqlCommand())
{
cmd.CommandType = CommandType.StoredProcedure;
SqlParameter p = new SqlParameter("@drug_name", Prefixtetxt);
//cmd.Parameters.AddWithValue("@drug_name", p);
cmd.Parameters.Add("@drug_name", SqlDbType.VarChar);
using (SqlDataReader reader = cmd.ExecuteReader())
{
returnList.Add(Convert.ToString(reader["drug_name"]));
}
}
}
return returnList;
}
}
}
来自 Sql Server 的 sproc
create proc spFindAllDrugs
@drug_name varchar(100)
as
begin
select distinct drug_name
from rx
where drug_name like '%' + @drug_name + '%'
end