tags:

views:

40

answers:

1

Okay, so I have a Generic IList of custom objects that I want to use as a datasource for a repeater.

    Dim productRows As IList(Of MyCustomObject)()

   'fill list with data

    rptResults.DataSource = productRows
    rptResults.DataBind()

In the WebForm inside the repeater, I place this code:

<%# DirectCast(Container.DataItem, MyCustomObject).Title %>

And when I try to run it, I get the error "Unable to cast object of type 'System.Collections.Generic.List`1[MyCustomObject]' to type 'MyCustomObject'. ". Which makes sense, really.

What's the best way round this? Is there any way I can get the direct cast working? I'm loath to have to create a custom list item that implements IBinding or something and bind that directly, as that'll mean a lot of legacy changes which may create further bugs. Or is there a better way?

+2  A: 

Try this

<%# Bind("Title") %>'
Andrew