views:

12

answers:

1

I have a GridView which selectively binds to one of two ObjectDataSources. I make the switch in the Page_Load by setting GridView.DataSourceID. One of the data sources has parameters which refer to ControlIDs which don't always exist. Even if it's not set as a DataSourceID, the data source tries to get the values for the ControlIDs, throwing an exception.

Is there any way to disable the data source I don't need? I tried Dispose() and setting to null, but it still throws the error. Setting the param values OnSelecting would complicate things so I would like to avoid that if possible.

A: 

Instead of disposing, I did SelectParameters.Clear() and that took care of the problem.

Nelson
What if the ObjectDataSource SelectMethod is parameterless? the better approach might be use single ObjectDataSource and instead of selecting with which data source to bind grid with, configure the single data source appropriately in the code instead of markup..
Khurram Aziz
If it's parameterless then it won't have a `ControlParameter` and thus won't throw an Exception because of a missing control. I would rather keep it declarative because the list of parameters is very long.
Nelson