Adding controls to the ItemTemplate of a Repeater in a CompositeControl

Discussion in 'ASP .Net Building Controls' started by Nathan Sokalski, Dec 24, 2007.

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

    http://www.nathansokalski.com/
    Nathan Sokalski, Dec 24, 2007
    #1
    1. Advertising

  2. Nathan Sokalski

    Guest 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

    "Nathan Sokalski" <> wrote in message
    news:...
    > 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
    >
    > http://www.nathansokalski.com/
    >
    Guest, Dec 26, 2007
    #2
    1. Advertising

  3. 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" <> wrote in message
    news:...
    >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
    >
    > http://www.nathansokalski.com/
    >
    Coskun SUNALI [MVP], Dec 26, 2007
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Bennett Haselton
    Replies:
    1
    Views:
    5,332
    Joe Fallon
    Sep 24, 2004
  2. Mantorok

    Adding validators to CompositeControl

    Mantorok, Jun 15, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    635
    Mantorok
    Jun 15, 2006
  3. AC [MVP MOSS]
    Replies:
    2
    Views:
    533
    AC [MVP MOSS]
    Feb 13, 2007
  4. Nathan Sokalski
    Replies:
    2
    Views:
    1,113
    Coskun SUNALI [MVP]
    Dec 26, 2007
  5. Andy B
    Replies:
    1
    Views:
    988
    bruce barker
    Nov 15, 2008
Loading...

Share This Page