Asp.net ajax autocomplete无法使用AutoCompleteExtender

时间:2016-06-15 05:42:16

标签: c# asp.net ajax autocompleteextender

我想在文本框中实现ajax autocomplete功能,

我试过以下

<asp:TextBox ID="txtCountry" runat="server"></asp:TextBox>
<ajax:AutoCompleteExtender ID="AutoCompleteExtender1" runat="server" TargetControlID="txtCountry"
    ServicePath="~/App_Code/WebService.cs" MinimumPrefixLength="1" EnableCaching="true" CompletionSetCount="1"
    CompletionInterval="1000" ServiceMethod="GetCompletionList">
</ajax:AutoCompleteExtender>

并在Webservice.cs

我试过以下

[WebMethod]
public List<string> GetCompletionList(string prefixText)
{
    SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["dbconnection"].ToString());
        con.Open();
        SqlCommand cmd = new SqlCommand("select Company_name from Outword_CommonMST where Company_name  " +
                                                        "like '" + prefixText + "%' order by company_name", con);
        //cmd.Parameters.AddWithValue("@Name", prefixText);
        SqlDataAdapter da = new SqlDataAdapter(cmd);
        DataTable  dt = new DataTable( );
        da.Fill(dt);
        List<string> Company_name = new List<string>();
        for(int i=0;i<dt.Rows.Count;i++)
        {
            Company_name.Add(dt.Rows[i][1].ToString());
        }
        return Company_name;
    }
}

但是当我检查它时,它无效。

此外,当我在控制台中检查时,它正在提供类似

的内容
  

ScriptResource.axd?d = smCBrjG8b3peouydxeU-NDM-jIwTmeeFry083DH5OhjfnWTee0cYnYTLGZX9W7p4AmkPzE7GkZ-MoV ...:6076 POST http://localhost:55264/PSITERP%20lite/App_Code/WebService.cs/GetCompletionList 403(Forbidden)

请说明这里有什么问题

1 个答案:

答案 0 :(得分:1)

像这样:

<div(?:\s|>)