交换/禁用 ObjectDataSource
我有一个 GridView,它有选择地绑定到两个 ObjectDataSource 之一。我通过设置 GridView.DataSourceID 在 Page_Load 中进行切换。其中一个数据源具有引用 ControlID 的参数,但这些参数并不总是存在。即使未将其设置为 DataSourceID,数据源也会尝试获取 ControlID 的值,从而引发异常。
有什么办法可以禁用我不需要的数据源吗?我尝试了 Dispose() 并设置为 null,但它仍然抛出错误。设置参数值 OnSelecting 会使事情变得复杂,所以我想如果可能的话避免这种情况。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我没有进行处理,而是使用了
SelectParameters.Clear()
来解决这个问题。Instead of disposing, I did
SelectParameters.Clear()
and that took care of the problem.