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

Pass custom object parameter for Formtemplate insert and update bind fields

2 Answers 54 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Fred Mare
Top achievements
Rank 1
Fred Mare asked on 19 Nov 2010, 11:19 AM

Hi

 

I am using a FormTemplate and an objectdatasource to updateand insert items in my radGrid.

I would like to pass a custom object to my data object layer instead of a parameter for each bind field in the form template.

 

Currently I am creating my custom object in the UpdateCommand and InsertCommand and pass it to the inserting or updating event of the objectdataosurce using the page viewstate. I also remove the formtemplate required paramaters in the inserting and updating events. Is there a better way to do this?

 

protected void ObjectDataSource1_Inserting(object sender, ObjectDataSourceMethodEventArgs e)
      {
          //Remove parameters
          e.InputParameters.Remove("field1");
          e.InputParameters.Remove("field2");
          e.InputParameters.Remove("field3");
          e.InputParameters.Remove("field4");
          e.InputParameters.Add("customObject", (CustomObject)ViewState["customObject"]);
                        
      }

protected void radGrid__InsertCommand(object source, GridCommandEventArgs e)
       {
           GridEditableItem editedItem = e.Item as GridEditableItem;
           CustomObject customObject = new CustomObject();
             
           RadTextBox txtField1 = (RadTextBox)editedItem.FindControl("field1");
           RadTextBox txtField2 = (RadTextBox)editedItem.FindControl("field2");
           RadTextBox txtField3 = (RadTextBox)editedItem.FindControl("field3");
           RadTextBox txtField4 = (RadTextBox)editedItem.FindControl("field4");
           customObject.Field1 = txtField1.Text;
           customObject.Field2 = txtField2.Text;
           customObject.Field3 = txtField3.Text;
           customObject.Field4 = txtField4.Text;
           ViewState.Add("customObject", customObject);
            
       }

Thanks

2 Answers, 1 is accepted

Sort by
0
Accepted
Veli
Telerik team
answered on 24 Nov 2010, 04:05 PM
Hello Fred,

This is the most straightforward approach. RadGrid cannot generate or update your custom object automatically, so you need to get the edited/inserted values and initialize an instance of the data type yourself.

Greetings,
Veli
the Telerik team
Browse the vast support resources we have to jumpstart your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
0
Fred Mare
Top achievements
Rank 1
answered on 29 Nov 2010, 07:12 AM
Thank you very much
Tags
Grid
Asked by
Fred Mare
Top achievements
Rank 1
Answers by
Veli
Telerik team
Fred Mare
Top achievements
Rank 1
Share this question
or