Adding controls to the ItemTemplate of a Repeater in a CompositeControl

N

Nathan Sokalski

I am write a CompositeControl, and one of the controls being included is a
Repeater. This is my first time including a templated control in a control
other than a UserControl. I am not sure how to add controls to the templates
or how to do the databinding when using the Repeater (or any other templated
control) in a CompositeControl. Can somebody please help me here? Thanks.
 
G

Guest

Hi,

repeaters templates are ITemplates, so you can not add the controls
straightly to them, because ITemplate doesn't have a Controls collection.
Solution is simple, insert any control to Repeaters ItemTemplate (or any
other template), get the control in code by
Repeater.FindControl("YourControlID") and add your controls to it's Controls
collection. Use different ID's in each Template.

Regards,

Lukas Holota
 
C

Coskun SUNALI [MVP]

Hi Nathan,

You can create templates by implementing ITemplate interface. I will give
you a sample example below. All you need to do is to create your control
structure using the "container" control. "InstantiateIn" method will be
executed automatically when the RepeaterItem is created by the Framework.
You can set your template like this:

#######################
Repeater1.ItemTemplate = new MyRepeaterItemTemplate();
#######################

You can also create different kinds of constructors to deliver some data to
the template.

And the template class something like below:

#######################
public class MyRepeaterItemTemplate : ITemplate
{

#region ITemplate Members

public void InstantiateIn(Control container)
{
// do something else
container.Controls.Add(new LiteralControl("Some text"));
}

#endregion
}
#######################
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,734
Messages
2,569,441
Members
44,832
Latest member
GlennSmall

Latest Threads

Top