Last post Dec 11, 2008 07:32 AM by silverman71
Dec 10, 2008 11:04 AM|silverman71|LINK
I'm trying to create a databound composite control. I have created a few composite controls so I know how that works.
The databinding is a completley different task [:'(]
The documentation for this really isn't - anywhere !
I've gotten this far but seem to be missing something...
1. Inheriting from CompositeDataBoundControl
2. Creating an Item class and a Collection class for Items
3. Overriding CreateChildControls(datasource,databinding)
protected override int CreateChildControls(IEnumerable dataSource, bool dataBinding)
// If no datasource is used, create a standard calendar
if (dataSource == null)
// Count how many items we have
int itemCount = 0;
//Clears the Items collection ( creates it, if null )
if (dataSource != null)
IEnumerator e = dataSource.GetEnumerator();
object datarow = e.Current;
CalendarItem elem = new CalendarItem(itemCount,e.Current);
// Start building the hierarchy of controls
In the overriden CreateChildControls I try to get the data from the datasource. The problem is that my datasource is always null.
I've attached a SqlDataSource ( that works ) to the component in an .aspx page.
What I don't understand is when is the datasource bound. And probably a few things more that I don't get :(
Is there anyone that has a link to a good tutorial about this or some other reference that actually properly describes the whole process of creating a databound composite control ?
Thanks in advance
Dec 10, 2008 05:00 PM|Arrow|LINK
Check out this article by Dino Esposito,
http://msdn.microsoft.com/en-us/library/aa479016.aspx. It covers building a composite data-bound control.
Dec 11, 2008 07:32 AM|silverman71|LINK
That and some other research on the net made it work for me.
For others I can tell that it is very important how you add your controls.
My mistake was that I didn't add the controls the first time before I had bound the data to the control.
If you do it like that ASP.NET will not be able to track the ViewState of the control on postback.
Since PerformDataBinding calls TrackViewState the control needs to be in the Controls of your composite control before that occurs.