locked
Communication between field templates RRS feed

  • Question

  • User1980140492 posted

    Hey guys,

    I applied Stephen's blog post ( http://csharpbits.notaclue.net/2009/05/communicating-between-fieldtemplates-in.html ) to my project and it looked like everything worked the way I wanted it, until I saw that the communication between the field templates only happens with the first line in the grid. So I mean when you're doing an inline edit.

    I could not find the source of the problem so I decided to recreate Stephen's project ( the one on his blog ) and here the same thing happens. It all works perfectly with the first line in the grid and this everytime you switch between pages. What I also saw was that when editting at the bottom ( detailsview ) it actually does work the way it should.

    I'm using VS 2010 & .NET 4.0 so I guess that's where the problem lies allthough this should work here aswell, but does any of you know the solution?

    For ease of testing purposes you should recreate Stephen's project, just add reference to his ChangingAware library and mimic the other behavior and you'll see in less than 5 minutes time what I'm talking about.

    Thanks in advance,
    - Yannick

    Friday, July 8, 2011 4:39 AM

Answers

  • User-330204900 posted

    I'll try and build a working sample and post back but it will be when I have time.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, July 8, 2011 9:29 AM
  • User1980140492 posted

    Hmm nevermind :) it was my own stupid misstake ...  what you suggested works :)

    If anyone ever needs this, here's the new method:

    private IChangeNotifyingFieldTemplate GetParentControl()
            {
                if (ParentColumn != null)
                {
                    // get value of dev ddl (Community)
                    Control parentDataControl = this.GetContainerControl<DataBoundControl>();
                    IChangeNotifyingFieldTemplate parentControl = null;
    
                    if (parentDataControl is GridView)
                    {
                        parentDataControl = this.GetContainerControl<GridViewRow>();
                    }
    
                    var parentDynamicControl = parentDataControl.FindDynamicControlRecursive(ParentColumn.Name) as DynamicControl;
    
                    if (parentDynamicControl != null)
                        parentControl = parentDynamicControl.Controls[0] as IChangeNotifyingFieldTemplate;
    
                    return parentControl;
                }
                return null;
            }
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, July 8, 2011 10:31 AM

All replies

  • User-330204900 posted

    Hi Yannick, I have never tested that in a grid I would imagine that the issue is the first control it comes accross finding the parent is always the one in the first row. As it looks for a IDataBoundControl I think where as what you want for the grid is to look for a GridViewRow that way you will only be searching for the current row. That is my first guess.

    Friday, July 8, 2011 5:25 AM
  • User1980140492 posted

    Meaning I'll have to change the GetParentControl method in the ChildChangingAwareFieldTemplate class, but I guess that it wont work anymore in the detailsview then. Can you have different fieldtemplates for the form view and the grid view?

    Friday, July 8, 2011 6:19 AM
  • User-330204900 posted

    I would test to see if the returned control is a GridView if it is then search for GridViewRow.

    // get value of dev ddl (Community)
    Control parentDataControl = this.GetContainerControl<DataBoundControl>();
    
    if (parentDataControl is GridView)
        parentDataControl = this.GetContainerControl<GridViewRow>();
    

    I've not tested this but it sould work

     

     

    Friday, July 8, 2011 7:03 AM
  • User1980140492 posted

    I get what you mean and I've tested it, but I keep seeing that the parentcontrol its state is empty.

    Friday, July 8, 2011 9:07 AM
  • User-330204900 posted

    I'll try and build a working sample and post back but it will be when I have time.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, July 8, 2011 9:29 AM
  • User1980140492 posted

    Hmm nevermind :) it was my own stupid misstake ...  what you suggested works :)

    If anyone ever needs this, here's the new method:

    private IChangeNotifyingFieldTemplate GetParentControl()
            {
                if (ParentColumn != null)
                {
                    // get value of dev ddl (Community)
                    Control parentDataControl = this.GetContainerControl<DataBoundControl>();
                    IChangeNotifyingFieldTemplate parentControl = null;
    
                    if (parentDataControl is GridView)
                    {
                        parentDataControl = this.GetContainerControl<GridViewRow>();
                    }
    
                    var parentDynamicControl = parentDataControl.FindDynamicControlRecursive(ParentColumn.Name) as DynamicControl;
    
                    if (parentDynamicControl != null)
                        parentControl = parentDynamicControl.Controls[0] as IChangeNotifyingFieldTemplate;
    
                    return parentControl;
                }
                return null;
            }
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, July 8, 2011 10:31 AM
  • User-330204900 posted

    Excelent :)

    Friday, July 8, 2011 4:36 PM