Is it possible to stop ObjectDataSource from auto-binding?

Rusty Wizard picture Rusty Wizard · Aug 9, 2012 · Viewed 7.5k times · Source

I have a GridView to which I've using an ObjectDataSoure as the data source. The ObjectDataSource is taking in parameters from a TextBox and DropDownList which is then passed into the stored procedure. There is also a button called Search which can be used to force a refresh on the GridView by providing/changing values in the TextBox and/or DropDownList. However I noticed that if I changed the values I don't have to click on the Search button; simply clicking on the GridView causes a data bind.

Is there anyway to prevent this action while still using the ObjectDataSource?

Answer

Derek Hunziker picture Derek Hunziker · Aug 9, 2012

When you assign a DataSourceID on the GridView, the grid will automatically bind to the ObjectDataSource. You can simply omit that property on the GridView and wait until the Search button's click event to assign it.