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