こんにちは、autocompleteextender を使用してテキスト ボックスにデータを入力することができません。データはデータベースからフェッチされています。以下に私のコードを示します。どんな提案でも大歓迎です。ASP.Net コード:
<asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server" EnablePageMethods="true">
</asp:ToolkitScriptManager>
<div>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<br />
<asp:AutoCompleteExtender ID="AutoCompleteExtender1" UseContextKey="true" runat="server" CompletionInterval="10" TargetControlID="TextBox1" ServiceMethod="GetValues" MinimumPrefixLength="2" EnableCaching="false" CompletionSetCount="4">
</asp:AutoCompleteExtender>
</div>
C# コード:
[WebMethod]
[System.Web.Script.Services.ScriptMethod]
public static List<string> GetValues(string prefixText,int count)
{
List<string> lst = new List<string>();
SqlConnection connection = new SqlConnection("Data Source=172.22.1.189;Initial Catalog=M1022779;Integrated Security=True");
SqlCommand command = new SqlCommand();
command.Connection = connection;
command.CommandText = "select * from dept where dname like '%'+@Name+'%'";
command.Parameters.AddWithValue("@Name", prefixText);
SqlDataAdapter da = new SqlDataAdapter(command);
DataTable dt = new DataTable();
da.Fill(dt);
//Console.WriteLine(dt.Rows[0][0]);
for (int i = 0; i < dt.Rows.Count; i++)
{
lst.Add(dt.Rows[i][1].ToString());
}
return lst;
}