views:

537

answers:

2

What's the simplest way to add a new row to a Telerik RadGrid in ASP.NET from code behind?

+1  A: 

If you add a new item in the grid source and rebind the grid, this should do the trick (since the Telerik grid is data-bound control). To display the insertion form, set the MasterTableView.IsItemInserted property to true.

Dick

Thanks, there is no way to add the row without rebind?
Anders Eriksson
+1  A: 

The basics of adding a row are described in this demo from Telerik's website. Generally though, through the code behind, there are a few method that I've found that you need to make a telerik grid work:

  • RadGrid1_NeedDataSource - used for paging and on_load events
  • RadGrid1_UpdateCommand - updating a row
  • RadGrid1_ItemDataBound - bindingto a row item
  • RadGrid1_RemoveCommand - removing a row item

    GridEditableItem editedItem = e.Item as GridEditableItem;

Wil give you access to a row item. And:

editedItem.GetDataKeyValue()

will give you access to an id associted with each row item.

Good luck, and hope this helps out some.

Chris