New Row persist to datasource on cellvalue changed

2 posts, 0 answers
  1. Matthew
    Matthew avatar
    16 posts
    Member since:
    Oct 2010

    Posted 24 Nov 2011 Link to this post


    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?

  2. Jack
    Jack avatar
    2333 posts

    Posted 28 Nov 2011 Link to this post

    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,
    the Telerik team

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

Back to Top