I'm using ASP.NET AJAX Controls and Toolkit to autocomplete a TextBox
in a .aspx page. The TextBox
works as a search field in connection with a dropdown. Now I only want the autocomplete to show when a certain category from the dropdown is selected.
For autocomplete I've got this code
[System.Web.Services.WebMethod]
[System.Web.Script.Services.ScriptMethod]
public static string[] DepartmentAuto(string prefixText, int count)
{
string[] _strArray = { "Factory Management", "Housekeeping", "HR", "Industry Development"}
return _strArray;
}
And my dropdown/ textbox works like this
void Filter()
{
if (DropDownList1.SelectedValue.ToString() == "Title")
{
ObjectDataSource1.FilterExpression = "Title LIKE '%" + TextBox1.Text + "%' ";
}
else if (DropDownList1.SelectedValue.ToString() == "Department")
{
ObjectDataSource1.FilterExpression = "Department LIKE '%" + TextBox1.Text + "%' ";
}
}
I've tried to add the if statement to my autocomplete code like this
[System.Web.Services.WebMethod]
[System.Web.Script.Services.ScriptMethod]
public static string[] DepartmentAuto(string prefixText, int count)
{
if (DropDownList1.SelectedValue.ToString() == "Department")
{
string[] _strArray = { "Factory Management", "Housekeeping", "HR", "Industry Development"}
return _strArray;
}
}
But then I get two errors-
DepartmenAuto: not all code paths return a value
An object reference is required for the non-static field, method or property "DropdownList1"
Any help how I can do this?