Wednesday, October 11, 2006

Would the person who wrote ObjectDataSource please step forward?

I'd like the programmer of ObjectDataSource at Microsoft to write something in the comments about why on earth we cannot bind to any property of an instance that is not a value type. WHY? What were you thinking!?

For those not in the know about this, I should be able to write the following in ASP.NET when using an ObjectDataSource in a GridView: <%# Bind("SomeObject.Name") %>. In straight C#, this would translate to RowObject.SomeObject.Name. As it stands, you can only bind to value types in the properties of the RowObject. So I could do <%# Bind("Name") %> to get to RowObject.Name. But I can't get at any properties of that SomeObject. If I try that, I get the error "A call to Bind was not well formatted. Please refer to documentation for the correct parameters to Bind" when trying to build the project.

Folks, this makes ObjectDataSource worthless for any reasonable object model except the most basic of the basic. It means you have to tear your objects apart and hand them to the GridView, just as you'd have to do if you weren't using ObjectDataSource.

If someone has any other ideas about this besides subclassing ObjectDataSource, feel free to step forward. Otherwise, allow me to say "WTF?"

No comments: