If I have a class called “car” and this car class uses a SQL query to fill properties like ID, Name, Type, Model, Engine, and Size. How can I populate an asp:formview with that data?
I tried this:
Private currentCar As car
fvCarview.DataSource = currentCar
fvCarview.DataBind()
but I keep on getting this error:
Data source is an invalid type. It must be either an IListSource, IEnumerable, or IDataSource.
Any help would be appreciated!
Thanks
An easy way would be to use a
List(Of Car)with a single car in it or a singleIEnumerable(Car)viacarList.Where(Function(c) c.ID = carID). You could also use aSqlDataAdapterto fill aDataTableandtable.Where(Function(r) r.Field(Of Int32)("ID") = carID). Or just select the single car from database which is also the most efficiant way when you don’t need the complete list anyway:DataTable:
Here’s your custom Car-Class approach with a single car in a
List(Of Car):