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

New Row persist to datasource on cellvalue changed

1 Answer 47 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Matthew
Top achievements
Rank 1
Matthew asked on 25 Nov 2011, 02:45 AM
Hi,

I need a grid which will persist to the database every time a cell is edited
i've managed to achieve this for existing rows:
- handle the CellEndEdit event
- grab the DataBoundItem
- send it off to the data layer for updating

this does not work when editing cells in the "New row" as the DataboundItem property is null. I noticed that if i navigate to a different row, from this point the DataBoundItem is NOT null and updates will work.
Is there any way to make this happen on CellEndEdit, can i force the grid to create a new item in the datasource at this point instead of waiting for the user to navigate away from the row?

Thanks,
Matt

1 Answer, 1 is accepted

Sort by
0
Jack
Telerik team
answered on 28 Nov 2011, 10:34 AM
Hello Matthew,

By default, RadGridView creates a new record in the underlying data source when the cell data in "add new row" is validated. After validating the data you will be able to access cell values by using the DataBoundItem property. Before this you should access and modify data by using the Cells collection directly. Here is a sample:
void radGridView1_DefaultValuesNeeded(object sender, GridViewRowEventArgs e)
{
    e.Row.Cells["Name"].Value = "John Smith";
}

You can modify this behavior and create the data when clicking on the "add new row" by setting the AddNewBoundRowBeforeEdit property to true:
this.radGridView1.MasterTemplate.AddNewBoundRowBeforeEdit = true;

I hope this helps. 
 
Kind regards,
Jack
the Telerik team

Q3’11 of RadControls for WinForms is available for download (see what's new). Get it today.

Tags
GridView
Asked by
Matthew
Top achievements
Rank 1
Answers by
Jack
Telerik team
Share this question
or