DataBinding to an ArrayList

September 6, 2007

Maybe it’s because it’s late o’clock, but this one took me a while to figure out:

I have a DataList which is databound to an ArrayList containing objects of type MyType. I tried using something like this to print out the property MyProperty:

Text=’<%# DataBinder.Eval(Container.DataItem, MyProperty) %>‘/>

Which of course failed. All I needed to do was to change it to this:

Text=’<%# ((MyType)Container.DataItem).MyProperty %>‘/>

Note to self: don’t ever do it again!


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: