binding custom types to DataList

S

sklett

I have a collection of objects that I have bound to a DataList. My
collection is based on CollecionBase.
In the ItemTemplate for my DataList I have this:
<code>
<%#Container.DataItem("FileName")%>
</code>

FileName is a property of my class.

This generates an error:
DataListItem.DataItem' denotes a 'property' where a 'method' was expected

I'm not sure what I'm doing wrong, do you?
 
C

Craig Deelsnyder

I have a collection of objects that I have bound to a DataList. My
collection is based on CollecionBase.
In the ItemTemplate for my DataList I have this:
<code>
<%#Container.DataItem("FileName")%>
</code>

FileName is a property of my class.

This generates an error:
DataListItem.DataItem' denotes a 'property' where a 'method' was
expected

I'm not sure what I'm doing wrong, do you?

Are you using C#? If so, use brackets around the "FileName" instead. And
cast the expression to whatever type the item is (DataRowView, etc.)
 
C

Craig Deelsnyder

I have a collection of objects that I have bound to a DataList. My
collection is based on CollecionBase.
In the ItemTemplate for my DataList I have this:
<code>
<%#Container.DataItem("FileName")%>
</code>

FileName is a property of my class.

This generates an error:
DataListItem.DataItem' denotes a 'property' where a 'method' was
expected

I'm not sure what I'm doing wrong, do you?

Er, my reply to this post (which should be showing up soon): it should
say: cast only the Container.DataItem, e.g. if it was a DataRowView

((DataRowView)Container.DataItem)["FileName"]
 
S

sklett

Craig Deelsnyder said:
I have a collection of objects that I have bound to a DataList. My
collection is based on CollecionBase.
In the ItemTemplate for my DataList I have this:
<code>
<%#Container.DataItem("FileName")%>
</code>

FileName is a property of my class.

This generates an error:
DataListItem.DataItem' denotes a 'property' where a 'method' was
expected

I'm not sure what I'm doing wrong, do you?

Er, my reply to this post (which should be showing up soon): it should
say: cast only the Container.DataItem, e.g. if it was a DataRowView

((DataRowView)Container.DataItem)["FileName"]

I like your approach better then the eval method. Problem is, when I try to
cast my object I get a compiler error complaing that it doesn't know about
it. The class is defined in the same namespace as the aspx page, so I'm not
sure how else to make the page aware of class CGalleryItem.

Does that make sense?

Thank you for your responses,
Steve
 

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

Forum statistics

Threads
474,079
Messages
2,570,574
Members
47,205
Latest member
ElwoodDurh

Latest Threads

Top