473,516 Members | 3,248 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Adding controls to the ItemTemplate of a Repeater in a CompositeControl

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
nj********@hotmail.com
http://www.nathansokalski.com/
Dec 24 '07 #1
2 8147
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" <nj********@hotmail.comwrote in message
news:ur**************@TK2MSFTNGP05.phx.gbl...
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
nj********@hotmail.com
http://www.nathansokalski.com/
Dec 26 '07 #2
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" <nj********@hotmail.comwrote in message
news:ur**************@TK2MSFTNGP05.phx.gbl...
>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
nj********@hotmail.com
http://www.nathansokalski.com/
Dec 26 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
42554
by: Big D | last post by:
Hi all, I'm having a problem adding controls to a panel dynamically. I have a usercontrol that I create and try to add 5 times to the panel, but I only ever see the first control. I know it's the first, because a property of the userControl is to display it's name. The code I have is: //Add detatil widgets to the panel ...
2
3705
by: avivgur | last post by:
Hello, I am writing a program in Visual C# and I have encountered a problem. In my program I want to dynamically create a multitude of controls (thousands) on a form. The problem is that calling the Controls.Add() method several times or even calling the Controls.AddRange() method once can take a huge amount of time. Therefore, I would like to...
0
1195
by: Charlie | last post by:
Hi: I'm using the Repeater control to display one-to-many relationship between Customer, Orders and Order Items. To do this, I bind the control to Customer table to show customer data, then call a function from item template to generate Order and Order items which are returned as a string containing HTML markup tags. Since the Orders...
4
3600
by: MattB | last post by:
Hello. I'm creating a page to edit a person's record (name address, etc) using a DataGrid. I want the fields that can be edited to be created at runtime based on a list of columns in web.config. This is working fine, and I can add a control (TextBox or DropDownList) dynamically for the user to fill in a value. This works well for just adding...
3
2328
by: Ankit Aneja | last post by:
I have a strange situation and I have no idea how to solve this. Its a Recruitment Search Page,in the Admin Page, for every button click event the Admin Person has to create a checkbox on the users page. So whenever the Admin person comes to know about the new category in the market he will be adding as different Sub-Categories for example...
2
1475
by: Oleg Ogurok | last post by:
Hi all, Does anyone have example of adding controls on the client side (DHTML) and then persisting them as ASP.NET server controls on the server side? For example, a page has an <input> box for entering e-mail address and a button <Add more addresses>.
6
1514
by: crazyjh | last post by:
hello i want to add some controls in according of the time. but when the time change, i call the method again to add controls again,No effect! i think maybe i should unload the controls adding before,how can i unload it?? pls help me,thanks
3
5466
by: Mark Denardo | last post by:
I'm trying to dynamically create and add controls to a web page: Label obj1 = new Label(); DropDownList obj2 = new DropDownList(); Controls.Add(obj1); Controls.Add(obj2); But I get the following error when the DDL is added (but not the Label): "Control 'ctl07' of type 'DropDownList' must be placed inside a form tag
2
359
by: Chris Botha | last post by:
I am adding controls dynamically to the page as per the samples there are on the Web and it works - I can create text boxes, buttons, my own user controls, whatever, on the fly and initialize them and add them to a placeholder no problem. However when I post back and the page displays again then all of the controls are gone. I create them...
4
4455
by: Lewis Holmes | last post by:
Hi I have the following situation in one of my asp.net pages. The user can add multiple table rows to a form by selecting a button. These rows can contain asp.net controls. When this button is selected, the row is added using JavaScript. The script uses cloneNode to clone a hidden template row and all of its children and then adds the new...
0
7273
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7182
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7405
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7547
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5106
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3265
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
1620
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
823
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
487
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.