Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Building Controls > Dynamically adding controls to a data repeater

Reply
Thread Tools

Dynamically adding controls to a data repeater

 
 
Chris Kennedy
Guest
Posts: n/a
 
      06-05-2004
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.


 
Reply With Quote
 
 
 
 
John Saunders
Guest
Posts: n/a
 
      06-05-2004
"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/de...-us/cpguide/ht
ml/cpconkeyconceptsinwebformscontroldevelopment.asp)

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

ASP.NET Server Control Development Basics
(http://msdn.microsoft.com/library/de...-us/cpguide/ht
ml/cpconwebformscontroldevelopmentbasics.asp)

Developing a Composite Control
(http://msdn.microsoft.com/library/de...-us/cpguide/ht
ml/cpcondevelopingcompositecontrols.asp)

Design-Time Support for Web Forms
(http://msdn.microsoft.com/library/de...-us/cpguide/ht
ml/cpcondesign-timeforwebforms.asp)
--
John Saunders
johnwsaundersiii at hotmail


 
Reply With Quote
 
 
 
Reply

Thread Tools

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Adding controls to the ItemTemplate of a Repeater in a CompositeControl Nathan Sokalski ASP .Net Building Controls 2 12-26-2007 05:06 PM
Adding controls to the ItemTemplate of a Repeater in a CompositeControl Nathan Sokalski ASP .Net 2 12-26-2007 05:06 PM
Data and controls from dynamically added controls is rmoved on Submit David Hubbard ASP .Net 2 01-17-2006 06:52 PM
Adding external data into database data before it is sent to Control(Repeater, Datagrid, etc.) Neo Geshel ASP .Net 2 11-17-2005 12:53 AM
Adding controls to Repeater during runtime Charlie@CBFC ASP .Net 0 05-11-2004 05:06 PM



Advertisments
 



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