ASP.NET 2.0 DataBoundControls

When I first saw the DataBoundControl and DataSource controls in ASP.NET I thought it was a great idea. Upon futher review, why is it everytime I want to do something non-trivial with data-binding and controls the whole thing falls apart?

Finally today, it dawned on me, the real problem is not really the idea of creating generic data source controls, but the implmentation in ASP.NET 2.0 is too limited. In general data binding in ASP.NET is too wedded to the controls themselves. I'd like to use the data source binding scheme in my own list-like controls, but in order to use that functionality I have to derive from a DataBoundControl. But, I have my own control base class and I don't want to do that! And when you think about it, shouldn't the data gathering be as separate from the controls as possible? I think so.

Just off the top of my head, something like this would be really handy:

public class DataBoundControlHelper
{
    public string DataSourceID { ... }
}

public class MyControl : MySubclassOfControl
{
    private DataBoundControlHelper m_helper;
    public MyControl()
    {
        m_helper = new DataBoundControlHelper(this);
        m_helper.OnPeformSelect(Helper_PerformSelect);
    }

    public DataBoundControlHelper DataBinding {...}

    protected void Helper_PerformSelect(object sender, EventArgs e)
    {
        // do stuff that
    }
}

If I was using C++ maybe I could get around this multiple inheritence, but, now I'm stuck. I'm going to have to basically replicate all of the data binding logic from BaseDataBoundControl in my own control subclass. Yuck.


About this entry