Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / December 2007

Tip: Looking for answers? Try searching our database.

Adding controls to the ItemTemplate of a Repeater in a CompositeControl

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Nathan Sokalski - 24 Dec 2007 02:57 GMT
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.
Signature

Nathan Sokalski
njsokalski@hotmail.com
http://www.nathansokalski.com/

l.holota@hotmail.com - 26 Dec 2007 09:50 GMT
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

> 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.
Coskun SUNALI [MVP] - 26 Dec 2007 17:06 GMT
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
   }
#######################

Signature

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

>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.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.