AutoCompleteExtender and Collection of objects

  • Thread starter Thread starter Jeff
  • Start date Start date
J

Jeff

hi

vs2008

The code below is some code which is being executed when user types in a
textbox..
This method returns an array of strings which is shown as a dropdown list
added to the listbox...

As you see from the code below first a collection of Cars is added to the
CarCollection variable, and then a loop goes through all objects in that
collection and subtract the "make" of the car and add it to a string
array...

that's fine but each Car object contain's an Id which I want to get. Lets
say this AutoCompleteExtender shows a list of 5 strings. The user select one
of those string items. But the info in the textbox isn't saved to the
database, the "Id" is saved to the database.

any ideas how to get that "Id". I could for example when saving it perform a
select in the stored procedure which gets the "id", but I thought maybe
there are a better solution to this. I mean the "Id" is retrieved already so
hope I can avoid making another retrieve. In addition the Car object has
more info which I would like to be displayed when the user select a specific
car

any suggestions?

[WebMethod]
public string[] GetCompletionList(string prefixText, int count)
{
List<Car> CarCollection = Car.GetCars(prefixText, count);
List<string> Cars = null;
foreach (Car car in CarCollection)
{
Cars.Add(car.make);
}
return Cars.ToArray();
}
 
the autocomplete is not a list type control. its a free from textbox, that
calls the server to suggest longer alternatives to save typing. auto suggest
is a better name.



-- bruce (sqlwork.com)
 
Back
Top