Dynamically adding controls to a data repeater

Discussion in 'ASP .Net Building Controls' started by Chris Kennedy, Jun 5, 2004.

  1. 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.
    Chris Kennedy, Jun 5, 2004
    #1
    1. Advertising

  2. "Chris Kennedy" <> wrote in message
    news:...
    > 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)
    --
    John Saunders
    johnwsaundersiii at hotmail
    John Saunders, Jun 5, 2004
    #2
    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. Charlie@CBFC

    Adding controls to Repeater during runtime

    Charlie@CBFC, May 11, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    3,848
    Charlie@CBFC
    May 11, 2004
  2. Neo Geshel
    Replies:
    2
    Views:
    716
    Neo Geshel
    Nov 17, 2005
  3. David Hubbard
    Replies:
    2
    Views:
    614
    David Hubbard
    Jan 17, 2006
  4. Nathan Sokalski
    Replies:
    2
    Views:
    1,094
    Coskun SUNALI [MVP]
    Dec 26, 2007
  5. Nathan Sokalski

    Adding controls to the ItemTemplate of a Repeater in a CompositeControl

    Nathan Sokalski, Dec 24, 2007, in forum: ASP .Net Building Controls
    Replies:
    2
    Views:
    934
    Coskun SUNALI [MVP]
    Dec 26, 2007
Loading...

Share This Page