hi i am unbale to populate data to an textbox using autocompleteextender, the data is being fetch from the database. i a m giving the code of mine below. Any suggestions are welcome. ASP.Net code:
<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# code:
[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;
}