HighTechTalks DotNet Forums  

Adding controls to the ItemTemplate of a Repeater in a CompositeControl

ASP.net Building Controls microsoft.public.dotnet.framework.aspnet.buildingcontrols


Discuss Adding controls to the ItemTemplate of a Repeater in a CompositeControl in the ASP.net Building Controls forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
Nathan Sokalski
 
Posts: n/a

Default Adding controls to the ItemTemplate of a Repeater in a CompositeControl - 12-23-2007 , 08:57 PM






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.
--
Nathan Sokalski
njsokalski (AT) hotmail (DOT) com
http://www.nathansokalski.com/



Reply With Quote
  #2  
Old   
 
Posts: n/a

Default Re: Adding controls to the ItemTemplate of a Repeater in a CompositeControl - 12-26-2007 , 03:50 AM






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

"Nathan Sokalski" <njsokalski (AT) hotmail (DOT) com> wrote

Quote:
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.
--
Nathan Sokalski
njsokalski (AT) hotmail (DOT) com
http://www.nathansokalski.com/


Reply With Quote
  #3  
Old   
Coskun SUNALI [MVP]
 
Posts: n/a

Default Re: Adding controls to the ItemTemplate of a Repeater in a CompositeControl - 12-26-2007 , 11:06 AM



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
}
#######################

--
All the best,
Coskun SUNALI
MVP ASP/ASP.NET
http://sunali.com


"Nathan Sokalski" <njsokalski (AT) hotmail (DOT) com> wrote

Quote:
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.
--
Nathan Sokalski
njsokalski (AT) hotmail (DOT) com
http://www.nathansokalski.com/



Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.