This is a migrated thread and some comments may be shown as answers.

Help with SubObject Two Way Databinding

5 Answers 108 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Joshua Kent
Top achievements
Rank 1
Joshua Kent asked on 09 Sep 2009, 10:01 PM
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



5 Answers, 1 is accepted

Sort by
0
Joshua Kent
Top achievements
Rank 1
answered on 10 Sep 2009, 04:28 PM
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
0
Veli
Telerik team
answered on 15 Sep 2009, 06:24 AM
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.
0
Joshua Kent
Top achievements
Rank 1
answered on 15 Sep 2009, 02:25 PM
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
0
Veli
Telerik team
answered on 17 Sep 2009, 11:09 AM
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.
0
Joshua Kent
Top achievements
Rank 1
answered on 22 Oct 2009, 06:12 PM
Thanks, this helped a lot!!!
Tags
Grid
Asked by
Joshua Kent
Top achievements
Rank 1
Answers by
Joshua Kent
Top achievements
Rank 1
Veli
Telerik team
Share this question
or