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

Change ORM data source of grid from code behind

3 Answers 94 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Stephen
Top achievements
Rank 1
Stephen asked on 12 May 2009, 05:25 PM
Hi

Still getting used to ORM (open access) and have created a grid on a web  page that is changes its data source on a tab click and refreshes to show a single different table

The problem is when you try to edit an item in a grid row it produces an error;
"There was a problem extracting DataKeyValues from the DataSource. Please ensure that SDataKeyNames are specified correctly and all feilds exist in the Datasource."

I have not been able to degug to find what the values are.

It is coded in .net 3.5 with latest 2009 version of open access and rad grid

The technique to change data is in NeedDataSource as follows;

protected

 

void RadGridTable_NeedDataSource(object source, GridNeedDataSourceEventArgs e)
string cDataSourceTypeName = "RGLdata.TblContactType"  // the open access class where data stored
string cMasterTableViewDataKeyNames = "ContactTypeId"; // the primaary key feild in correct case with no spaces of the above table

 

 

 

 

OpenAccessDataSource1.TypeName = cDataSourceTypeName;
// blank all before add new

RadGridTable.DataSourceID =

"";

 

 

 RadGridTable.MasterTableView.DataSourceID =

"";

 

 

 RadGridTable.MasterTableView.DataKeyNames =

new string[] {};
 

 

 

// add correct sources
RadGridTable.DataSourceID =

 

"OpenAccessDataSource1" ;

 

RadGridTable.MasterTableView.DataSourceID =

 

"OpenAccessDataSource1";

 

RadGridTable.MasterTableView.DataKeyNames =

new string[] { cMasterTableViewDataKeyNames };

No databind or datarebind is called in needdatasource

Any ideas on what to change, to enable edit in grid !

Rgds
Stephen

 

 

 

 

 

3 Answers, 1 is accepted

Sort by
0
Stephen
Top achievements
Rank 1
answered on 12 May 2009, 05:59 PM
Hi

Found another thread on forum (last one of 99) and it gave what looked like a good solution, wheich was adding 

OpenAccessDataSource1.DataBind() ;

But unfortunately it did not work!

Rgds
Stephen

0
Zoran
Telerik team
answered on 13 May 2009, 01:35 PM
Hello Stephen,

The reason for this behavior is that you set the properties of the OpenAccessDataSource in the NeedDataSource event handler but clicking edit on the RadGrid causes postback and the data you have set to the data source properties( TypeName, etc..) is lost. If you want to do various CRUD operations with different persistent types you should use multiple datasources and only change the RadGrid.DataSourceID. The other way is not to use data source at all but to use additional code-behind logic in the NeedDataSource, InsertCommand, UpdateCommand etc. That way is quite more challenging so for simple scenarios as yours I'd suggest you use multiple OpenAccessDataSource components which represent your desired persistent types and depending on your logic just set the RadGrid.DataSourceID property for the appropriate data source.

Greetings,
Zoran
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Stephen
Top achievements
Rank 1
answered on 13 May 2009, 04:29 PM
Hi Zoran

Thanks for comment only 8 tables so will produce 8 

telerik

 

:OpenAccessDataSource in apsx

Hope that in future relases that the 

 

telerik

 

:OpenAccessDataSource can be created in code behind as would help provide more generic solution

Again thanks as it is now up and working!

Rgds
Stephen

 

Tags
Grid
Asked by
Stephen
Top achievements
Rank 1
Answers by
Stephen
Top achievements
Rank 1
Zoran
Telerik team
Share this question
or