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

RadGrid's Datasource which is Datatable doesnt get updated

4 Answers 170 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Jaya
Top achievements
Rank 1
Jaya asked on 24 May 2012, 08:10 AM
I assigned Datatable variable as Datasource for RADGrid in needDataSource event. When editing the row item in the Grid, those changes are not saved back to Datatable automatically. Is there anyway the edits directly go back to datatable and I can save in to database later, only if the user clicks on save by calling Datatable.GetChanges(). for now I have used following code in UpdateCommand event to save the changes back to datatable.

In the following code dtaddress is my datatable

 

protected void rgAddress_UpdateCommand(object sender, GridCommandEventArgs e)

{


GridEditableItem editedItem = e.Item as GridEditableItem;

editedItem.OwnerTableView.AllowAutomaticUpdates = true // this line didnt work

 

 

 

int row = editedItem.RowIndex - 3; //removed header rows.. this is ugly

dtaddress.Rows[row]["address1"] = (editedItem["Address1"].Controls[0] as TextBox).Text;

dtaddress.Rows[row]["address2"] = (editedItem["Address2"].Controls[0] as TextBox).Text;

dtaddress.Rows[row]["city"] = (editedItem["City"].Controls[0] as TextBox).Text;

 dtaddress.Rows[row]["state"] = (editedItem["State"].Controls[0] as TextBox).Text;

 dtaddress.Rows[row]["country"] = (editedItem["Country"].Controls[0] as TextBox).Text;

 dtaddress.Rows[row]["ZipCode"] = (editedItem["ZipCode"].Controls[0] as TextBox).Text;*/

e.Item.OwnerTableView.Rebind();

Also even after it comes out of updatecommand code block, the edit mode doesnt go away. Please help.


4 Answers, 1 is accepted

Sort by
0
Jayesh Goyani
Top achievements
Rank 2
answered on 24 May 2012, 01:20 PM
Hello Jaya,

Please remove below code line.
e.Item.OwnerTableView.Rebind();

Note : it will rebind grid and then remove edit item automatically.


OR

GridEditableItem editedItem = e.Item as GridEditableItem;
............
...........
editedItem.IsInEditMode = false;
e.Item.OwnerTableView.Rebind();

Note : you can also use : "RadGrid1.MasterTableView.ClearChildEditItems();"  or "RadGrid1.MasterTableView.ClearEditItems();"

Thanks,
Jayesh Goyani
0
Jaya
Top achievements
Rank 1
answered on 24 May 2012, 06:17 PM
None of the options you said worked...

first of all IsInEditMode is a readonly . you can't assign a value false to it..

Is there a way for datatable to be automatically updated without me assigning edited values for each field in the updatecommand event? Can anyone help?
0
Jayesh Goyani
Top achievements
Rank 2
answered on 24 May 2012, 07:18 PM
Hello Jaya,

Sorry for this,
Please use below property,
item.Edit = false;


Thanks,
Jayesh Goyani
0
Eyup
Telerik team
answered on 29 May 2012, 07:51 AM
Hi Jaya,

You could use declarative datasource for handling the editing automatically as demonstrated in the following demo:
 Grid / Automatic Operations

If you will use Advanced ( NeedDataSource ) databinding, however, you could use OnUpdateCommand server event of the grid as shown in this article:
 Manual Insert/Update/Delete operations 

Give it a try and let me know what the result is.

Regards,
Eyup
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Tags
Grid
Asked by
Jaya
Top achievements
Rank 1
Answers by
Jayesh Goyani
Top achievements
Rank 2
Jaya
Top achievements
Rank 1
Eyup
Telerik team
Share this question
or