I have a fairly complex display (a scorecard) that is a web user control (containing many various type asp.net controls) on a page. It is populated by a custom data collection (an object I've named "TPD"). This works great to display one scorecard at a time. The problem is that I want to display multiple (a variable number) scorecards on a single page.
I've looked at repeater controls but my display (the scorecard) does not fit the conventional iterative controls (list control, datagrid etc) and I don't think that route would work for me anyway.
I have done similar in the past without using a web user control as follows:
- Loop through the data and each time through the loop append a string with standard html (no web user control, no asp.net controls) representing a scorecard.
- Assign the completed string to the text property of a literal control which renders it to the screen.
Another solution (that I find basically unworkable but might explain what I am trying to do!) is as follows:
- Put 50 (or some large number) instances of the web user control on the page and hidden.
- Then loop through the data and create x number of data objects (the "TPD's" I mentioned earlier)
- Populate and make visible as many of the web user controls as necessary.
This seems messy and inefficient to me! Am I missing something completely obvious here?
The best way to accomplish the wanted behaviour would be to:
a) create the user control in such a way that the data is set and then databound.
b) add one user control to the page OR put it within a repeater.
c) retrieve one instance OR a collection of instances and bind these to your user control.
If your user control allows to bind itself to a datasource then your control behaves just like all the existing webcontrols.