views:

278

answers:

3

If I have a control on a page that has its Datasource set to a DataReader, does that control consume the reader at the time the Datasource is set, or does the datareader continue to exist until Databind has been executed?

What actually happens under the covers when Databind is executed?

+1  A: 

It should be consumed at the time DataBind is executed.

rslite
+1  A: 

Depending on the Control, DataBind() will Bind the Data to the Control. It does this by Iterating through the DataSource and create the Html and other Controls that are needed.

For a DropDownList, DataBind() will create the ListItem for each record in a DataSet or each Element in an ArrayList.

Later the Render method is call on the DropDownList, which returns the Html for a Select tag. It also creates the Html for each ListItem by returning Option tags inside the Select tag.

For a Label, DataBind() will set the Text to the value you pulled from the Database (for example).

If you don't call DataBind() for the specific control, you can also make sure that your DataSource is set for a control and call Page.DataBind(). This will go through the Controls in the Page and call all of the DataBinds for each Control.

RedWolves
A: 

What is the control doing with the datareader during databind? Does it copy it into its internal structures and dispose of the datareader then render?

If I have 10 controls on a page and set the datasource on each to a different datareader, then called page.databind, will the datareaders exist the entire time (from the point of creation until the point where the page.databind completes it's processing)?

Gern Blandston