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

Databinding to collection

1 Answer 73 Views
Grid
This is a migrated thread and some comments may be shown as answers.
JMKeynes
Top achievements
Rank 1
JMKeynes asked on 14 Oct 2008, 01:17 AM
I am having problems with updating/inserting/deleting objects in a RadGrid whose data source is bound to a collection. Particulars:

- The collection is bound to the RadGrid when NeedDataSource fires as I am using a treeview control to filter the results in the RadGrid.
Protected Sub AccountDetails_NeedDataSource(ByVal source As Object, ByVal e As Telerik.Web.UI.GridNeedDataSourceEventArgs) Handles AccountDetails.NeedDataSource
accts = af.GetAccounts(TreeNav.SelectedValue) 'where af.GetAccounts returns a collection of accounts
AccountDetails.DataSource = accts
End Sub
- Only some of the fields within the object are displayed in the RadGrid (pk is not displayed); several fields are not primative types (two fields are also collections).

- Update/Insert functions are located in the BLL and take the edited/selected object as a parameter.

- I cannot seem to retrieve the selected/edited object from the RadGrid programmatically (datasource is null?!?), and when I try to get information by populating a hashtable with ExtractValuesFromItem (less than ideal as I do not have all the data displayed in the grid), the key values are null as well.

Would someone be able to provide insight on how I can accomplish retrieving the original/edited objects from the RadGrid? Are there any code examples that I missed while searching? Many thanks.

1 Answer, 1 is accepted

Sort by
0
Maria Ilieva
Telerik team
answered on 16 Oct 2008, 12:18 PM
Hello JMKeynes,

In order to have your application working properly first you should add the PK into the DataKeyNames collection of the MasterTableView. In this help topic you will find how to retrieve the primary key for selected items. Additionally RadGrid.EditItems is a collection of all items that are currently in edit mode and here you can find how to retrieve original values for edited item.
Also please note that the ExtractValuesFromItem() method returns the new values only for the editable columns. In order to extract all values you can set ForceExtractValue="Always" for each readonly column

Greetings,
Maria Ilieva
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
Grid
Asked by
JMKeynes
Top achievements
Rank 1
Answers by
Maria Ilieva
Telerik team
Share this question
or