I've got a dropdown/ textbox combination to enable the user to filter the data of a GridView.
So the user would select the option 'Job Title' in the dropdown and then enter the Job title they are looking for in the textbox. However, I want to give the user a list of suggestion of Job titles. I've been trying to do so with AutoCompleteMode set to SuggestAppend and a AutoCompleteSource set to custom but this hasn't been working and I get the error that AutoCompleteMode etc. doesn't exist in the current context.
This is the code in my TextBox1 Changed event :
TextBox1.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
t=TextBox1.AutoCompleteSource = AutoCompleteSource.CustomSource;
AutoCompleteStringCollection DataCollection = new AutoCompleteStringCollection();
addItems(DataCollection);
TextBox1.AutoCompleteCustomSource = DataCollection;
And this to set the autocomplete options:
var source = new AutoCompleteStringCollection();
source.AddRange(new string[]
{
"Marketing",
"Engineer",
"Medical",
"Insurance",
});
I'm currently filtering the data with the dropdown list like this:
void ResultsFilter()
{
if (DropDownList1.SelectedValue.ToString() == "Name")
{
ObjectDataSource1.FilterExpression = "Name LIKE '%" + TextBox1.Text + "%' ";
}
else if (DropDownList1.SelectedValue.ToString() == "JobTitle")
{
ObjectDataSource1.FilterExpression = "JobTitle LIKE '%" + TextBox1.Text + "%' ";
}
}
Ideally I would include the auto complete only if "JobTitle" is selected. Any suggestions on how to achieve this?