Change ORM data source of grid from code behind

4 posts, 0 answers
  1. Stephen
    Stephen avatar
    15 posts
    Member since:
    May 2007

    Posted 12 May 2009 Link to this post

    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

     

     

     

     

     

  2. Stephen
    Stephen avatar
    15 posts
    Member since:
    May 2007

    Posted 12 May 2009 Link to this post

    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

  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Zoran
    Admin
    Zoran avatar
    534 posts

    Posted 13 May 2009 Link to this post

    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.
  5. Stephen
    Stephen avatar
    15 posts
    Member since:
    May 2007

    Posted 13 May 2009 Link to this post

    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

     

Back to Top