I would ask you to define what a "data object" is
I’m not sure anymore. First I thought “data object” is a data source
that can supply data to ObjectDataControl ( thus data object would be
class we specify with TypeName attribute ), but perhaps “Data object”
is the data which data source supplies to ObjectDataControl. Here’s
the exact quote ( perhaps you can figure out what the quote meant by
“data object” ):
"Earlier, you saw an example that allowed users to browse a list of
cities in different regions using two linked controls—a DropDownList
and a GridView. Best of all, this example could be created using a
SqlDataSource or an ObjectDataSource; either way, it doesn’t require
any custom code.
As convenient as this example is, it presents a problem that’s
difficult to fix. Because it’s impossible to create a drop-down list
that doesn’t have a selected item (unless it’s empty), the first city
in the list is automatically selected. Many web applications use a
different behavior and add an extra item at the top of the list with
text such as “(Choose a City)”. Selecting this first item has no
effect.
Additionally, you might want to add an item that allows you to see
every city in a single list.
So, how can you implement this model with data binding?
One of the few weaknesses in the data binding model is that you never
explicitly handle or create the data object that’s bound to the
control. As a result, you don’t have the chance to add an extra item.
In fact, this example has two challenges—determining how to add the
extra options to the list and reacting when they are selected to
override the automatic query logic."
Yes.
Note that "never explicitly create" is a rather meaningless statement.
Someone has to create it somewhere, and since it's presumably a
collection of objects of some class that you define, then you'll have
to create it.
If we are talking about ObjectDataSource, then no, since it's not a
"data object" (I think that you might actually be meaning "business
object" by that).
I didn’t mean to imply that ObjectDataSource was a “data object” i.e.
”data access component”. By “data access component” ( i.e. “data
object” ) I meant a class that we specify in TypeName attribute –>
thus in case of <TypeName=”EmployeeDB”>, the data object is EmployeeDB
instance ( though as noted in the beginning of my post, the term
“data object” perhaps really means data returned by EmployeeID class )
The class that you feed to ObjectDataSource is not itself a business object -
it's just a glue.
By “class you feed to” are you referring to EmployeeDB or to a class
which EmployeeDB instance returns to ObjectDataSource ?
I strongly suspect that they rather mean not to manually fill the
control with child controls (i.e. iterate over the list, create a
ListItem for each element and add it to the ListBox, and so on). If
you're dealing with business objects, they are supposed to be created
(or otherwise obtained) by the business layer anyway, so you just ask
it to "get all customers with first name X". It will still have to
create those objects somewhere, but it won't be in UI code.
For this purpose it doesn't.
It this point I would ask you to define what a "data object" is
See the beginning of my post
but
whatever it may be, I don't see why you wouldn't be able to do that. I
mean, you can certainly write:
listBox.DataSource = new[] { new { Name = "John", Age = 31 }, new
{ Name = "Jane", Age = 27 }, ... };