Hi, I'm using an AutoCompleteExtender for an ASP.NET project of mine, and it's pulling the fields to be shown fine. However, when the user chooses an autocomplete suggestion, I need the function to pull another field from the row (the 'ID' column which is the primary key), as that what is the necessary field used to display the relevant data.
Here is my code
public string[] GetAutoComplete(string prefixText)
{
int count = 10;
string sql = "SELECT * FROM SageAccount WHERE Name LIKE @prefixText";
SqlDataAdapter da = new SqlDataAdapter(sql, "My Connection String(changed due to personal info being shown)");
da.SelectCommand.Parameters.Add("@prefixText", SqlDbType.VarChar, 50).Value = prefixText + "%";
DataTable dt = new DataTable();
da.Fill(dt);
string[] items = new string[dt.Rows.Count];
int i = 0;
foreach (DataRow dr in dt.Rows)
{
items.SetValue(dr["Name"].ToString(), i);
i++;
}
return items;
}
EDIT: Some modified code I am trying:
public string[] GetAutoComplete(string prefixText, int count)
{
string sql = "SELECT * FROM SageAccount WHERE Name LIKE @prefixText";
SqlDataAdapter da = new SqlDataAdapter(sql, "Con string");
da.SelectCommand.Parameters.Add("@prefixText", SqlDbType.VarChar, 50).Value = prefixText + "%";
DataTable dt = new DataTable();
da.Fill(dt);
List<string> Names = new List<string>();
//string[] items = new string[dt.Rows.Count];
int i = 0;
foreach (DataRow dr in dt.Rows)
{
Names.Add(AjaxControlToolkit.AutoCompleteExtender.CreateAutoCompleteItem(dr["Name"], dr["ID"].ToString());
//items.SetValue(dr["Name"].ToString(), i);
}
return Names.ToArray();
The issue I have here is that it gives me the error:
The best overloaded method match for 'AjaxControlToolkit.AutoCompleteExtender.CreateAutoCompleteItems(string, string)' has some invalid arguements'
Any ideas? Many thanks