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

OpenAccessDataSource.Selecting

1 Answer 83 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Brandon
Top achievements
Rank 1
Brandon asked on 24 Apr 2010, 10:53 PM
The issue I am having is when binding an OpenAccessDataSource control to a RadComboBox, I am receiving this error:  "The 'IObjectScope' is already closed."  This error message only occurs when I try to set a WhereParameter's DefaultValue in the OpenAccessDataSource.Selecting event.  In my database, I have a Company table.  I also have a ProductCategory table, which is a detail to the Company table.  Finally, I have a Product table that is a detail to the ProductCategory table.  My schema is as follows:

Company
int Id
string CompanyName

ProductCategory
int Id
int CompanyId
string CategoryName

Product
int Id
int CategoryId
string ProductName

At the top of my Page, I have two RadComboBox controls.  They are used for filtering data in a grid that sits below the two RadComboBox controls.  One RadComboBox contains a list of Company objects, and the other contains a list of ProductCategory objects.

The ProductCategory RadComboBox is tied to an OpenAccessDataSource who's Where property is "CompanyId == @CompanyId."  The CompanyId parameter has a default value of 0, and its source is set to "None."  In the OpenAccessDataSource.Selecting event, I use the following code:

        protected void ComboCategoryDataSource_Selecting(object sender, Telerik.OpenAccess.OpenAccessDataSourceSelectingEventArgs e) 
        { 
            SiAuto.Main.EnterMethod("ComboCategoryDataSource_Selecting"); 
            ComboCategoryDataSource.WhereParameters["CompanyId"].DefaultValue = UserSession.CompanyId.ToString(); 
            SiAuto.Main.LeaveMethod("ComboCategoryDataSource_Selecting"); 
        } 
 

Setting the DefaultValue of the parameter results in the OpenAccessDataSource firing a second time.  This is resulting in the RadComboBox being DataBound twice.  My log looks like this:

"Entering method: ComboCategoryDataSource_Selecting"
    "Entering method: ComboCategoryDataSource_Selecting"
    "Leaving method: ComboCategoryDataSource_Selecting"
    "Entering method: ComboCategoryComboBox_DataBound"
    "Leaving method: ComboCategoryComboBox_DataBound"


"Leaving method: ComboCategoryDataSource_Selecting"
"Entering method: ComboCategoryComboBox_DataBound"
"Leaving method: ComboCategoryComboBox_DataBound"




1 Answer, 1 is accepted

Sort by
0
Serge
Telerik team
answered on 29 Apr 2010, 07:46 AM
Hello Brandon,

The event selecting is not to be used to change the default value of a parameter. If you want to filter based on some external event or property, you can, but it should be outside of the selecting event handler. For example in the page load. The issue here is that setting the parameter causes instant re-evaluation of the data source, this being - creating of the scope, if one does not exist, executing the query and disposing of the scope.

The issue here is due to the fact that you are changing the values of parameters of the datasource that threw this event, if you were to however change the value of a parameter from another datasource everything would work.

Hope this helps.

Have a great day,
Serge
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
General Discussions
Asked by
Brandon
Top achievements
Rank 1
Answers by
Serge
Telerik team
Share this question
or