DictionaryBase and Repeaters

I’ve been struggling to databind a custom collection built off DictionaryBase to a Repeater. In my other custom collections that used CollectionBase, I could just cast the Container.DataItem to the underlying type and access the class’s properties. When I tried to do the same thing for my DictionaryBase collection, it kept giving me casting errors.

I tried casting the DataItem to the collection itself and using keys and values. The Web wasn’t particularly helpful. In explaining it to a coworker, who helpfully rubber ducked for me, I realized that I needed to cast the DataItem to a DictionaryEntry and then cast the value of that DictionaryEntry to my underlying type. Duh!

Here’s the syntax, with any confidential bits removed:

Advertisements

%d bloggers like this: