A gentleman in my ASP.NET 2.0 class a while ago asked me how to access the underlying object used for the ObjectDataSource control. Suppose you have some code in App_Code like so:
public DataSet SelectDataSet()
// code that populates the dataset...
DataSet ds = GetPopulatedDataSet();
// supporting methods here...
Now on the .aspx page we have an ObjectDataSource control as follows:
Notice the OnSelected attribute points to a method called ObjectDataSource1_Selected. This is the event where we can get access to the underlying data object. Here is the code for the event handler:
(object sender, ObjectDataSourceStatusEventArgs e)
DataSet underlyingDataSet = e.ReturnValue as DataSet;
// use the underlyDataSet...
The key to getting access to the underlying object is calling the ReturnValue off of the ObjectDataSourceStatusEventArgs object. ReturnValue is typed as Object, so it is necessary to cast to what the underlying data-type is. In the above example, the underlying data-type is a DataSet.