Blog de Francisco Velázquez

otro blog personal

Repeater dentro User Control

leave a comment »

Como crear controles de usuario que se componen de un Repeater y queremos iniciarlos desde fuera.

<%@ Control Language="C#" AutoEventWireup="true"  CodeBehind="ExRepeater.ascx.cs"
Inherits="TestUserControls.ExRepeater" ClassName="ExRepeater" %>

<script runat="server"></script>

<asp:Repeater ID="repeater" runat="server">
<%#((RepeaterItem) Container).DataItem.ToString() %>
</ul> </div>


public partial class ExRepeater : System.Web.UI.UserControl
protected void Page_Load(object sender, EventArgs e)

public object DataSource
Control c = FindControl("repeater");
return ((Repeater)c).DataSource;
Control c = FindControl("repeater");
((Repeater)c).DataSource = value;

En la página en el fichero aspx (o porque no, otro control) tendremos que referencial al control que contiene el Repeater:

 <%@ Reference Control="~/ExRepeater.ascx" %> 

Y en el código:

protected void Page_Load(object sender, EventArgs e)
if (!IsPostBack)
Control c = FindControl("form1");

string[] list = new string[2] { "elem1", "elem2" };
Control uc2 = LoadControl("~/ExRepeater.ascx");
((ExRepeater)uc2).DataSource = list;



Written by fravelgue

March 18, 2010 at 10:39 pm

Posted in Uncategorized

Tagged with , ,

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: