简体   繁体   English

在ASP.NET中没有Web服务的自动完成文本框

[英]AutoComplete TextBox without Webservices in ASP.NET

I am trying to set autocomplete on textbox. 我正在尝试在文本框中设置自动完成功能。 I have used this example: http://sapnashukla.blogspot.com/2014/05/to-create-autocomplete-textbox-without.html 我使用了以下示例: http : //sapnashukla.blogspot.com/2014/05/to-create-autocomplete-textbox-without.html

I can't get a result. 我没有结果。 When I trying to type text I am getting this result after TextBox: 当我尝试键入文本时,在TextBox之后得到以下结果:

Type test
<
!
D
O
C
T
Y
P
E
h
t
m
l
<
>
and etc..

What I should do for it? 我应该怎么做?

Somebody can explain and help me? 有人可以解释和帮助我吗?

I have tried this too: aspx.cs 我也尝试过:aspx.cs

public partial class manage : System.Web.UI.Page { 公共局部类管理: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> GetCompletionList(string prefixText, int count)
{
    return AutoFillProducts(prefixText);

}

private static List<string> AutoFillProducts(string prefixText)
{
    using (SqlConnection con = new SqlConnection())
    {
        con.ConnectionString = ConfigurationManager.ConnectionStrings["BNConnectionString"].ConnectionString;

        using (SqlCommand com = new SqlCommand())
        {
            com.CommandText = "select person from table where " + "person like @Search + '%'";

            com.Parameters.AddWithValue("@Search", prefixText);
            com.Connection = con;
            con.Open();
            List<string> countryNames = new List<string>();
            using (SqlDataReader sdr = com.ExecuteReader())
            {
                while (sdr.Read())
                {
                    countryNames.Add(sdr["person"].ToString());
                }
            }
            con.Close();
            return countryNames;


        }

    }
}  

} }

aspx: aspx:

<%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="manage.aspx.cs" Inherits="XX.Mobilus.manage" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajaxToolkit" %>


<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server">

    <asp:TextBox ID="TextBox1" runat="server" AutoPostBack="true"></asp:TextBox>
    <ajaxToolkit:AutoCompleteExtender ID="TextBox1_AutoCompleteExtender" runat="server" MinimumPrefixLength="1" EnableCaching="true" CompletionSetCount="1" 
        CompletionInterval="1" ServiceMethod="GetCompletionList" UseContextKey="True" TargetControlID="TextBox1">
    </ajaxToolkit:AutoCompleteExtender>
</asp:Content>

the blog had only one(1) parameter from its function 该博客的功能只有一个(1)参数 在此处输入图片说明

, have you tried removing the ", int count"? ,您是否尝试过删除“,int count”?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM