我的AJAX自動完成功能未與用戶控制工作,但是當我有一個正常的ASP.NET頁面中使用它,它工作得很好:AJAX自動完成不在用戶控件內部工作爲什麼?
[System.Web.Script.Services.ScriptMethod()]
[System.Web.Services.WebMethod]
public static List<string> GetCity(string prefixText, string contextKey)
{
DataTable dt = new DataTable();
string constr = ConfigurationManager.ConnectionStrings["ERPConnection"].ToString();
SqlConnection con = new SqlConnection(constr);
con.Open();
string CmdText = "select name+ '-' + ' ['+CONVERT(VARCHAR, custid) +']'as name from ht_cust where name like @City+'%' and EmpID [email protected]";
SqlCommand cmd = new SqlCommand(CmdText, con);
cmd.Parameters.AddWithValue("@City", prefixText);
cmd.Parameters.AddWithValue("@EmpId", contextKey);
SqlDataAdapter adp = new SqlDataAdapter(cmd);
adp.Fill(dt);
List<string> CityNames = new List<string>();
for (int i = 0; i < dt.Rows.Count; i++)
{
CityNames.Add(dt.Rows[i][0].ToString());
}
return CityNames;
}
aspx code
<asp:UpdatePanel ID="UpdatePanel7" runat="server">
<ContentTemplate>
<asp:TextBox ID="txtCity" runat="server" UseContextKey="true" onkeyup="SetContextKey()" CssClass="input-1" Width="200px"></asp:TextBox>
<ajaxToolkit:AutoCompleteExtender ID="AutoCompleteExtender1" runat="server" TargetControlID="txtCity" MinimumPrefixLength="1" EnableCaching="true" CompletionSetCount="1" CompletionInterval="1000" ServiceMethod="GetCity" UseContextKey="true" CompletionListCssClass="autocomplete_completionListElement">
</ajaxToolkit:AutoCompleteExtender>
</ContentTemplate>
</asp:UpdatePanel>
請幫助我。 – 2014-11-25 12:41:22
代碼在哪裏? – xxxx 2014-11-25 12:42:22
先分享你的代碼 – 2014-11-25 12:51:25