binding custom types to DataList

  • Thread starter Thread starter sklett
  • Start date Start date
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?
 
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.)
 
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"]
 
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
 
Back
Top