Musings of Geekdom by Eric Newton

tail /var/log/thoughts
posts - 88 , comments - 41 , trackbacks - 68

BoundFields... when will we ever be able to use them properly?

When using BoundFIelds and domain objects... BoundFields use some algo that can't traverse the object hierarchy.

What am I talking about?  Take for instance a Northwind database, with certain objects mapped to data tables:

public class Customer
    public int CustomerId;
    public IList<Order> Orders;

When binding to a list of Orders in a gridview:

int customerId = int.Parse(selCustomer.SelectedValue);
IList<Customer> customersList = CustomerService.GetCustomersWithOrders();
this.GridView1.DataSource = customersList;

<asp:GridView runat=server id=GridView1>
<asp:BoundField DataField=CustomerId />
<asp:BoundField DataField=Orders.Count />  <!--   CAN'T WORK -->
<asp:TemplateField><ItemTemplate><%# Eval("Orders.Count") %></ItemTemplate></asp:TemplateField> <!-- DOES WORK -->

I keep posing the question to ASP.Net Program Manager ScottGu, but can't seem to get a response.  A feedback item was created to address this, yet it seems very low on the priority list. 

In all my experience, I cannot understand why such an important feature, needed by anybody using an actual domain model with objects, cannot use BoundFields out-of-the-box.  A "workaround" is to use the TemplateField and Eval... but thats just a poor hack.  You don't get any SortExpression support.  Before ASP.Net AJAX Extensions, you couldn't even use the ClientSide callback framework with GridViews that contain TemplateFields.  You'd get an error saying TemplateFields weren't supported... pfft!

This is really disappointing... I'm using NHibernate to do the OR/Mapping and when I pull these fully hydrated objects from NHibernate queries, I still have to find a way to "flatten" the objects before they hit GridViews.  LINQ has this ability, but I'm not cleared to use LINQ on this current project.

I say we need to step up the level of discontent with certain features... If enough people complain and validate the problem (via the feedback item) hopefully it'll get fixed in the next 10 years.

In the interim, has anybody recoded BoundFields (perhaps using Mono source code as a template?) to properly evaluate nested Properties on objects?

Has anybody found a decent solution around this problem?

UPDATE: I'm creating a feedback item to re-address this.  Link will be here.

Print | posted on Wednesday, February 28, 2007 11:26 AM |



# re: BoundFields... when will we ever be able to use them properly?

I'm surprised they haven't fixed this given how mature the platform is.
5/11/2007 3:56 AM | Chui Tey

# re: BoundFields... when will we ever be able to use them properly?

I completely agree that BoundFields should traverse the object Hierarchy. This becomes very apparent when using nested LINQ objects. I developed a crude workaround which I posted on the feedback link listed in this article, Hopefully someone on the development team will decide to implement a similar approach in the BindField class so that it works properly.
12/26/2007 4:56 PM | Jeremy
Comments have been closed on this topic.

Powered by: