Dynamically adding controls to a data repeater

Ask a Question related to ASP.NET Building Controls, Design and Development.

  1. #1

    Default Dynamically adding controls to a data repeater

    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 Guest

  2. Similar Questions and Discussions

    1. Adding controls dynamically to a datagrid
      Hi, We have a requirement, where based on the UI type selected in a dropdown, a control should get added to the column of a grid dynamically. For...
    2. Dynamically Adding Controls
      I am trying to dynamically add controls to my page, but am having trouble with controls such as buttons. I have been able to add simple controls...
    3. dynamically adding user controls
      I have a web form that has a button called "Add Blank Row". Every time this button is pressed a new "blank row" user control should be added to the...
    4. Dynamically adding different controls to different rows in DataGrid does not work
      Hi! I've got a datagrid which I dynamically want to add controls to, and the type of control depends on user rights for the item shown in the...
    5. ANNOUNCEMENT : Samples for Datagrid, Datalist, Data Repeater controls
      hi all, Check this link for updated scrollable grid sample and download gridtest.zip from my site for the source....
  3. #2

    Default Re: Dynamically adding controls to a data repeater

    "Chris Kennedy" <chrisknospam@cybase.co.uk> wrote in message
    news:OqFlzNvSEHA.808@tk2msftngp13.phx.gbl...
    > 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
    ([url]http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/ht[/url]
    ml/cpconkeyconceptsinwebformscontroldevelopment.asp)

    Control Execution Lifecycle
    ([url]http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/ht[/url]
    ml/cpconcontrolexecutionlifecycle.asp?frame=true)

    ASP.NET Server Control Development Basics
    ([url]http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/ht[/url]
    ml/cpconwebformscontroldevelopmentbasics.asp)

    Developing a Composite Control
    ([url]http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/ht[/url]
    ml/cpcondevelopingcompositecontrols.asp)

    Design-Time Support for Web Forms
    ([url]http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/ht[/url]
    ml/cpcondesign-timeforwebforms.asp)
    --
    John Saunders
    johnwsaundersiii at hotmail


    John Saunders Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139