Help with SubObject Two Way Databinding

6 posts, 0 answers
  1. Joshua Kent
    Joshua Kent avatar
    5 posts
    Member since:
    Jul 2009

    Posted 09 Sep 2009 Link to this post

    I have an object that has two complex subobjects that are references to other objects.

        [Telerik.OpenAccess.Persistent(IdentityField = "deploymentID")] 
        public class Deployment 
        { 
            enum DeploymentStatus { Offline = 0, Running = 1, Deploying = 2 }; 
     
            private int deploymentID; 
            public int DeploymentID 
            { 
                get { return deploymentID; } 
                set { deploymentID = value; } 
            } 
     
            private Application deployedApplication; 
            public Application DeployedApplication 
            { 
                get { return deployedApplication; } 
                set { deployedApplication = value; } 
            } 
     
            private Server deployedServer; 
            public Server DeployedServer 
            { 
                get { return deployedServer; } 
                set { deployedServer = value; } 
            } 
    ... 


    I want the Grid to allow me to create, edit and delete this object. I have utilized the GridDropDownColumn

    <Columns> 
            <telerik:GridBoundColumn DataField="DeploymentID" DataType="System.Int32" HeaderText="DeploymentID" ReadOnly="True" SortExpression="DeploymentID" UniqueName="DeploymentID"
            </telerik:GridBoundColumn> 
            <telerik:GridDropDownColumn DataField="DeployedServer" HeaderText="Server" UniqueName="DeployedServer" DropDownControlType="DropDownList" DataSourceID="odsServers" ListTextField="ServerName" ListValueField="ServerID"></telerik:GridDropDownColumn> 
            <telerik:GridBoundColumn DataField="BuildServerURI" HeaderText="BuildServerURI" SortExpression="BuildServerURI" UniqueName="BuildServerURI"
            </telerik:GridBoundColumn> 
            <telerik:GridBoundColumn DataField="CurrentBuild" DataType="System.Int32" HeaderText="CurrentBuild" SortExpression="CurrentBuild" UniqueName="CurrentBuild"
            </telerik:GridBoundColumn> 
            <telerik:GridBoundColumn DataField="Location" HeaderText="Location" SortExpression="Location" UniqueName="Location"
            </telerik:GridBoundColumn> 
            <telerik:GridTemplateColumn DataField="Application" UniqueName="TemplateColumn"
            </telerik:GridTemplateColumn> 
        </Columns> 


    Of course this doesn't work because when editing this the GridDropDownColumn doesn't return the Server object it returns the ServerID (int).

    What is the best way to accomplish what I want? Any suggestions?

    I have tried creating a DeployedServerID property that would grab the object when passed an id from the dropdown. But then I get a OpenAccess error that two different ObjectScopes tried to manage the same object.

    private Server deployedServer; 
            public Server DeployedServer 
            { 
                get { return deployedServer; } 
                set { deployedServer = value; } 
            } 
     
            public int DeployedServerID 
            { 
                get 
                { 
                    if (deployedServer == null
                        return -1; 
                    else 
                        return deployedServer.ServerID; 
                } 
     
                set 
                { 
                    deployedServer = (from servers in DataModel.ObjectScope().Extent<Server>() where servers.ServerID == value select servers).First<Server>(); 
                } 
            } 


    Thanks,
       Josh



  2. Joshua Kent
    Joshua Kent avatar
    5 posts
    Member since:
    Jul 2009

    Posted 10 Sep 2009 Link to this post

    Any thoughts? I am still trying to figure out the best way to accomplish this with as little modification on the page itself. I thought this would be a feature in the grid that I might be missing.

    Josh
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Veli
    Admin
    Veli avatar
    2002 posts

    Posted 15 Sep 2009 Link to this post

    Hello Joshua,

    For editing a sub-object, it is best recommended that you use a separate form with the object properties. Then when you have created/updated and saved your server object, you need to find its ID in the dropdown column in RadGrid. Back in your update command, you need to find your server object by the selected ID and set it as a property to your updated parent object.

    Greetings,
    Veli
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  5. Joshua Kent
    Joshua Kent avatar
    5 posts
    Member since:
    Jul 2009

    Posted 15 Sep 2009 Link to this post

    Are there any examples of this in the demos? Although I think I am following what you are saying it would help illustrate it to me.

    Thanks again for your time,
       Josh
  6. Veli
    Admin
    Veli avatar
    2002 posts

    Posted 17 Sep 2009 Link to this post

    Hi Joshua,

    You can find attached a small web site I have created that demonstrates this. Some sample object factory is also included. Note that I have used two different ways of editing sub-objects of the main data object. In the first example, I create a template column where in the EditItemTemplate, I have editing fields bound to the sub-property of the data item. In the second case, I use an automatic data column (GridNumericColumn) with DataField="Stock.Quantity" that automatically allows me to show the value of the sub-property in the edit form.

    Back in the code-behind I use the UpdateCommand and InsertCommand events to extract the edited values straight into a data entity object (Product) and then update my data source and grid.

    Check the example out and let me know if further clarification is required.

    Sincerely yours,
    Veli
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  7. Joshua Kent
    Joshua Kent avatar
    5 posts
    Member since:
    Jul 2009

    Posted 22 Oct 2009 Link to this post

    Thanks, this helped a lot!!!
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017