container.dataitem cast throws exception

H

hsomob1999

I have a class, lets call it Schmuck. It has 2 public properties Name
(string) and active (boolean). When I bind to a Repeater, like so:
<%#container.dataitem("Name")%> i get the following error: No default
datamember found for type Schmuck. The Schmucks are in a ArrayList.
When I use DataBinder.Eval, i have no prob. But for say the boolean
Active property, I want to pass to a function like so:
<%#fx(CBool(container.dataitem("Active")))%> so i want to get away from
the Eval syntax ( for overhead reasons as well ). But why am i gettin
this error. Thanks for any advice......
 
M

Marina

What about using :container.dataitem.Name.

I think DataItem returns whatever object is being bound to. If you are
binding to a datatable, each dataitem is a DataRow, which happens to have an
indexer where you can index by column name.

Since you are binding to a collection of Schmucks, the DataItem should be a
Schmuck object, so you should be able to call .Name on it. You might have
to cast it to a Schmuck first.
 
T

Teemu Keiski

Correct,

just to add that when you bind to a DataTable, DataView etc the type of item
is always DataRowView (type of item in DataView). With dataReader it is
System.Data.Common.DBDataRecord. Of course with custom collection, it is the
type of the collection item. :)
 
H

hsomob1999

ok, thats sounds good. I dont have .NoT with me now bit will try when I
get home and let ya know hot it worked. It makes sense though because
the error says ".... no default property ..." that should have told me
it was trying to do a Object("index") type lookup.
Also, Marina that last paragraph sounds funny, with the Schmuck this
and Schmuck that. HA!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top