Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

What causes an ObjectDataSource to bind?

Status
Not open for further replies.

tshad

Programmer
Jul 15, 2004
386
US
I have a grid that has an ObjectDataSource. I don't assign the DataSourceID Declaratively.

As soon as I set the Datasource in my code (from a button event), it binds at that point and the ObjectCreated event fires.

But I don't have to do a DataBind().

If I do:

Code:
         this.mGridView.DataSourceID = mObjectDataSource2.ID;
         mGridView.DataBind();

or

Code:
         this.mGridView.DataSourceID = mObjectDataSource2.ID;
         //mGridView.DataBind();

Either way, it binds/fires.

Does it happen just by setting the DataSourceID?

If I wanted it to fire again, would I just have to reassign the DataSourceID to get it to fire?

Thanks,

Tom
 
Here is what seems to happen.

If the DataSourceID is not set - nothing will cause the ODS to fire.

If the DataSourceID is set already and the grid is not visible, Setting DataBind() will cause the ODS to fire. And each time the DataBind() is run the grid will fire. But setting the DataSourceID by itself will not cause the ODS to fire if the grid is not visible.

If the grid is visible, setting the DataSourceID will cause the ODS to fire. Setting the DataSourceID again will cause the ODS to fire again. Neither time was DataBind() called. As long as the grid is visible, each time you assign the DataSourceID, the ODS will fire - even if the DataSourceID is the same.

If you set the grid to not visible, no amount of setting the DataSourceID will cause the ODS to fire. Even if you set the DataSourceID then set the grid to visible. The grid must be visible at the time the DataSourceID is set for the ODS to fire without the DataBind().

The DataBind() will cause the ODS to fire every time whether the grid is visible or not as long as the DataSourceID has been set at least once.

Is there anything else that would cause it to fire?

I haven't seen this specified anywhere before and was surprised it wasn't.

Tom
 
I would recommend that you stay away from all of the DataSourceControls and build your own DAL. DataSource Controls are good for very simplistic pages, but once you need to do something more complex, they become useless. Not to mention, you cannot debug them in any way.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top