1
我试图找到我的答案在很多网站,但我觉得每一件事情是在我的代码正确的,但仍然是自动完成扩展不起作用。自动完成扩展工作不
<asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods = "true">
</asp:ScriptManager>
<asp:TextBox ID="txtName" runat="server" Width="190px" CssClass="TextBox"></asp:TextBox>
<cc1:AutoCompleteExtender
ID="AutoCompleteExtender1" ServiceMethod="GetNamesList"
MinimumPrefixLength="1"
CompletionInterval="1000" EnableCaching="true" CompletionSetCount="10"
TargetControlID="txtName" UseContextKey="True"
runat="server">
</cc1:AutoCompleteExtender>
[System.Web.Script.Services.ScriptMethod()] [System.Web.Services.WebMethod]
public string[] GetNamesList(string prefixText, int count, string contextKey)
{
DataSet dtst = new DataSet();
SqlConnection sqlCon = new SqlConnection(System.Configuration.ConfigurationManager.AppSettings["ConStr"]);
string strSql = "SELECT FirstName FROM finex.tbl_SenderInfo WHERE FirstName LIKE '" + prefixText + "%' ";
SqlCommand sqlComd = new SqlCommand(strSql, sqlCon);
sqlCon.Open();
SqlDataAdapter sqlAdpt = new SqlDataAdapter();
sqlAdpt.SelectCommand = sqlComd;
sqlAdpt.Fill(dtst);
string[] cntName = new string[dtst.Tables[0].Rows.Count];
int i = 0;
try
{
foreach (DataRow rdr in dtst.Tables[0].Rows)
{
cntName.SetValue(rdr["FirstName"].ToString(), i);
i++;
}
}
catch { }
finally
{
sqlCon.Close();
}
return cntName;
}
感谢您的回复。你解决了我的问题。它在任何网站都没有解释。 – Sara
很高兴帮助。因为它解决了您的问题,请考虑接受答案,如果您将鼠标悬停在答案的左上角附近,您应该看到一个可以点击接受的暗箭头。 – PeterJ