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

[Solved] TwoWay binding whole DataItem in FormTemplate

2 Answers 114 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Softec
Top achievements
Rank 1
Softec asked on 29 Sep 2009, 11:09 AM
Hi

How can I bind the whole Container.DataItem to my Control in the FormTemplate? I have a UserControl for editing my object (in this case Person) and would like to reuse this in the EditFormSettings of the RadGrid but can't achieve this in a TwoWay mode. 

My code so far:
  <EditFormSettings> 
                <FormTemplate> 
                    <uc:GridButtons ID="GridButtons2" runat="server" Position="Top" />     
                        <data:PersonPanel runat="server" ID="PersonPanel" DataSource='<%# Container.DataItem %>' 
                            AddCss="panel" GroupingText="Personendaten"  />               
                    <uc:GridButtons ID="GridButtons1" runat="server" Position="Bottom" />       
                </FormTemplate> 
            </EditFormSettings> 

GridButtons is just a UserControl with the Edit/Canel buttons (top and bottom) whereas PersonPanel is my control which takes a Person object and gives a Person object back (DataSource Property). The Propblem is that the Container.DataItem expression is only OneWay, how could I achieve this in both ways so the RadGrid gets the updated Object back?

Thanks for help!

2 Answers, 1 is accepted

Sort by
0
Iana Tsolova
Telerik team
answered on 02 Oct 2009, 08:54 AM
Hello Studach,


Please check out this blog post for more information on how achieve automatic insert, update and delete with UserControl edit form for RadGrid.

Additonal information on user control edit forms for RadGrid can be found in the below online resources:
http://www.telerik.com/help/aspnet-ajax/grdcustomeditforms.html
http://demos.telerik.com/aspnet-ajax/grid/examples/dataediting/usercontroleditform/defaultcs.aspx

Give it a try and let me know how it goes.

Best wishes,
Iana
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
Softec
Top achievements
Rank 1
answered on 05 Oct 2009, 03:21 PM
I solved it by creating a property on my class which represent itself and copying the needed properties in the set accessor, a little bit ugly but this was the fastest way to achieve this...
Now i can bind to the Self property

Markup:
 <EditFormSettings>  
                <FormTemplate>  
                    <uc:GridButtons ID="GridButtons2" runat="server" Position="Top" />      
                        <data:PersonPanel runat="server" ID="PersonPanel" DataSource='<%# Bind("Self") %>'  
                            AddCss="panel" GroupingText="Personendaten"  />                
                    <uc:GridButtons ID="GridButtons1" runat="server" Position="Bottom" />        
                </FormTemplate>  
            </EditFormSettings>  

Dummy code:
public class Person 
  public Person Self  
   {  
     get { return this; } 
     set  
     { 
         // copy the needed properties 
     } 
Tags
Grid
Asked by
Softec
Top achievements
Rank 1
Answers by
Iana Tsolova
Telerik team
Softec
Top achievements
Rank 1
Share this question
or