views:

90

answers:

2

What is the format for databinding to a complex "object"? I have a linq to sql class that has containment, i.e object.containedobject.

I want to reference the sub objects fields declarative.

So I've tried my MySubField.MyBasicProperty and that did not work, as well as, MySubField_MyBasicProperty.

Thanks for any help!

A: 

I found my answer, it is a problem with boundfield class and not databinding.

http://www.iridescence.no/post/FixingBoundFieldSupportforCompositeObjects.aspx

Curtis White
This introduced another problem in that updates no longer work. Suggestions?
Curtis White
A: 

I found solution and sharing for anyone who comes after me in the future.

You need to override the objectdatasource updating method to replace the param names. This is only possible if the objectypename property of the objectdatasource is not set or else they will be read only.

Here is my example:

protected void ObjectDataSource1_Updating(object sender, ObjectDataSourceMethodEventArgs e)
    {
        foreach (string currentKey in e.InputParameters.Keys)
        {
            if (currentKey.Contains("."))
            {
                string newKey = currentKey.Replace(".", "_");
                object myValue = null;

                if (e.InputParameters[currentKey] != null)
                    myValue = e.InputParameters[newKey];
                if (e.InputParameters.Contains(newKey))
                    e.InputParameters.Remove(newKey);

                e.InputParameters.Add(newKey, myValue);
                e.InputParameters.Remove(currentKey);

            }
        }
Curtis White
One other thing, should not modify a collection in a foreach so that should be fixed.
Curtis White