How to persist child controls in a CompositeDataBoundControl

331 Views Asked by At

The documentation for the CompositeDataBoundControl class (http://msdn.microsoft.com/en-us/library/ms366539(v=vs.100).aspx) states the following:

This is the base class that extends the DataBoundControl class, providing the following functionality:

  • Implements the typical code required by composite controls, including the code that restores the control's child control hierarchy from view state after a postback is made.
  • Binds to an IEnumerable data source and enumerates the data to build a control tree.
  • Serves as the basis for data-bound controls, such as GridView and DetailsView.

Can anyone explain or show an example of how to create a CompositeDataBoundControl that will retain its controls after PostBack without manually calling DataBind? My example is too complicated to post, but for example, if you bind a ListView, each item will be rendered after PostBack. This documentation seems to indicate that this will be handled automatically when inheriting from this class, but I haven't been able to make that work.

I can see that CreateChildControls is called after every postback even if I don't call DataBind, but that the data source is is an IEnumerable of null objects (a DummyDataSource with the same amount that were passed in the original datasource prior to the postback). It seems that I should be doing something with this collection but I'm not sure what since the type of control to create depends on the type of that item (in this case, I'm binding to a List of PropertyInfo and creating a certain class depending on an attribute on the property).

Thanks for any help you can provide!

0

There are 0 best solutions below