Last post Jul 11, 2012 08:19 AM by arobas123450
Jul 04, 2012 09:03 AM|arobas123450|LINK
Hello, I have the following problem. First Excuse-me for my bad English.
I'm developping a custom server control, it has to do his job totaly programmatically thanks server control Attributes.
This control embed a Repeater, I have implemented Itemplate in order to "feed" my Repeater.
Is it possible to feed programmatically my repeater with user controls ?
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="myClass.ascx.cs" Inherits="myClass" %>
<asp:Label ID="Title" Text='<%# Bind("Title") %>' runat="server"></asp:Label>
Jul 04, 2012 11:03 AM|Mudasir.Khan|LINK
this can be achieved easily by creating dynamic controls
foreach(var row in rows)
lbl = new Label();
lbl.Text = row.ToString();
Jul 05, 2012 12:52 PM|arobas123450|LINK
Thanks for your reply.
What about usercontrols in your example ? I know that is possible with server controls. Have I misunderstood something ?
Jul 05, 2012 09:58 PM|Decker Dong - MSFT|LINK
If you want to dynammically add controls to the Repeater，I suggest you：
1）First please add a Panel in the itemTemplate of your Repeater；
2）Then in the Repeater_ItemDataBound event，plz handle each RepeaterItem by using the event and find out the Panel inside and dynamically add server-side controls……
void R1_ItemDataBound(Object Sender, RepeaterItemEventArgs e)
// This event is raised for the header, the footer, separators, and items.
// Execute the following logic for Items and Alternating Items.
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
((e.Item as RepeaterItem).FindControl("Id of Panel") as Panel).Controls.Clear();
((e.Item as RepeaterItem).FindControl("Id of Panel") as Panel).Controls.Add(……);
PS：Considering it that your newly-added controls without "memory" of remembering things because each time when binding it will be disposed and renew one……So please use another Session or ViewState to remember these values if you want to assign to them ……
Jul 11, 2012 08:19 AM|arobas123450|LINK
Thanks, I will try.