Chris Kennedy said:
I would like to create a composite control based on a data repeater how do I
dynamically add and bind child controls to it? I imagine this is not a one
post answer so any pointers to books or resources to developing such a
control in vb.net would be great. Regards, Chris.
The basic idea is to do programatically what you would have done in the
..aspx file. So, for instance:
<asp:Repeater runat="server" id="myRepeater" ...>
<ItemTemplate>
<asp:Label runat="server" id="myLabel" Text="Label Text" />
</ItemTemplate>
</asp:Repeater>
Programatically:
Repeater myRepeater = new Repeater();
myRepeater.Id = "myRepeater";
myRepeater.ItemTemplate = new MyItemTemplate();
---
private class MyItemTemplate : ITemplate
{
void ITemplate.InstantiateIn(Control container) {
Label myLabel = new Label();
myLabel.Id = "myLabel";
myLabel.Text = "Label Text";
container.Controls.Add(myLabel);
}
}
If the repeater is the only control in your composite, then your new control
can simply derive from Repeater. If you need more than one, your new control
should go ahead and create a composite control.
Here are some references:
Developing ASP.NET Server Controls
(
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/ht
ml/cpconkeyconceptsinwebformscontroldevelopment.asp)
Control Execution Lifecycle
(
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/ht
ml/cpconcontrolexecutionlifecycle.asp?frame=true)
ASP.NET Server Control Development Basics
(
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/ht
ml/cpconwebformscontroldevelopmentbasics.asp)
Developing a Composite Control
(
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/ht
ml/cpcondevelopingcompositecontrols.asp)
Design-Time Support for Web Forms
(
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/ht
ml/cpcondesign-timeforwebforms.asp)