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!