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

how do I insert a row into radgrid without databind?

1 Answer 136 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Ron
Top achievements
Rank 1
Ron asked on 03 Sep 2010, 04:50 PM
I have a RadGrid that displays rows with textboxes for the user to enter qty's of an item they want to purchase.  If an item doesn't exist in the grid, I need the user to have the ability to add it to the radgrid without losing values entered into the other rows.  My question is how do I insert a row into the grid while keeping the current state of the grid?

Could I fill a datatable from RadGrid1 somehow then add a row to the datatable?

1 Answer, 1 is accepted

Sort by
0
Veli
Telerik team
answered on 08 Sep 2010, 12:05 PM
Hello Ron,

This scenario is not supported by RadGrid. To show the insert form and allow your user to enter a new record, RadGrid needs to rebind. Rebinding recreates all rows and controls inside them, thus losing the values the user has already entered.

To prevent this from happening, you need to save the new values before showing the insert form in RadGrid and then restore these values back to the textboxes once the grid has rebound and is showing the insert form. To do that you can use RadGrid's ItemCommand event to save the edited values, and ItemDataBound to restore the saved data:

protected void RadGrid1_ItemCommand(object sender, GridCommandEventArgs e)
{
    if (e.CommandName == RadGrid.InitInsertCommandName)
    {
        //save the edited values from all items here
    }
}
 
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
{
    if (e.Item is GridDataItem)
    {
        //restore the edited values to this item if there is any
    }
}


Regards,
Veli
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
Grid
Asked by
Ron
Top achievements
Rank 1
Answers by
Veli
Telerik team
Share this question
or