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

Assign DataItem when in edit mode

1 Answer 87 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Grooverinthesouth
Top achievements
Rank 1
Grooverinthesouth asked on 14 Jan 2009, 04:02 PM
I have a Radgrid which binds to a dataset to display four columns per row of a database table. This table is in fact much larger and contains many foreign key references.

If I select a row to edit I would like to extract the datakey(PK) and fetch the full business object with all related objects (foreign key objects) and assign it to the DataItem object of the GridEditFormItem object. I have databinding expressions in my page which I would like to keep which are set to bind to a business object graph in the Edit form.

My reason for not initially binding to the full object is the size and number of database calls required to fetch each object and related objects to simply display four properties in the grid in order to decide which object to edit.

How would I achieve the above scenario without manually doing a findcontrol for each control in my edit form template and assigning each property to each control as I already have the databinding syntax in the edit form ?

Example of implementation:
protected void Grid_OnRowEditing(object sender, ???args e)????? {  
      string primaryKey = e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["PrimaryKey"].ToString();  
 
BusinessObject ob = MyDataManager.GetBusObjectByPrimaryKey(primaryKey);  
e.Item.DataItem = (object)ob;  
 
//// The EDIT form would then bind to the above object and NOT the Dataset used to display the grid data.  
{}

1 Answer, 1 is accepted

Sort by
0
Nikolay Rusev
Telerik team
answered on 19 Jan 2009, 11:58 AM
Hello,

I've prepared sample application which demonstrates how you can attain similar functionality.
Basically you need to set DataItem on ItemEvent and extract newly entered data on UpdateCommand.
You can find the demo project attached to this post.

Sincerely yours,
Nikolay
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
Grid
Asked by
Grooverinthesouth
Top achievements
Rank 1
Answers by
Nikolay Rusev
Telerik team
Share this question
or