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

Update(Command) with Custom Object how?

1 Answer 110 Views
Grid
This is a migrated thread and some comments may be shown as answers.
alsi
Top achievements
Rank 1
alsi asked on 06 Dec 2008, 01:13 AM
Hi All!

I have the following problem:
I wrote a Generic class called Demo. It has three properties (get, set) and has LoadAll and Update functions from/into database.

List<Demo> demo = IDemoFactory.LoadAll(); //gives all the items from a table.

In RadGrid NeedDataSource event:
radGridDemo.DataSource = demo;

and now what I need to know how can I do:
I change the properties of the selected (edited) object and run Update Command -> radGridDemo_UpdateCommand(object source, GridCommandEventArgs e) fired. and I need my edited Custom Demo object somehow in the following way.
Demo demo = e.Item.DataItem as Demo;
IDemoFactory.Update(demo);

Is it possible to do on the way mentioned above or I need to set the edited properties on a Demo type object and than i need to give it to my Update function?
I have 40 properties and hard to do...
I have the same question about InsertCommand.

I hope U understand my question.
thanks,
g.

1 Answer, 1 is accepted

Sort by
0
Accepted
Rosen
Telerik team
answered on 08 Dec 2008, 04:08 PM
Hello,

You can use GridEditableItem's UpdateValues method in order to populate your object's properties. Similar to the following:

protected void grdOrder_UpdateCommand(object source, GridCommandEventArgs e)  
{  
        SimpleData data = new SimpleData();  
        ((GridEditableItem)e.Item).UpdateValues(data);  
//.. rest of the updating code  


Kind regards,
Rosen
the Telerik team

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