Can a Repeater control repeat an .ascx?

A

Alessandro Zifiglio

hi, its pretty simple and i dont think there is any articles online to
showcase this. I am pasting a simple test with 1 user control( that contains
a single textbox, whose text property is populated from the repeaters
databound datasource). The user control is contained within the repeaters
ItemTemplate. Also look up this reference on msdn since the example code
might help you :
http://msdn2.microsoft.com/en-us/library/system.web.ui.webcontrols.repeater.itemtemplate.aspx

Regards,

Alessandro Zifiglio
http://www.AsyncUI.net


in your parent page .aspx :
----------------------------
<%@ Register Src="WebUserControl.ascx" TagName="WebUserControl"
TagPrefix="uc1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Repeater ID="Repeater1" runat="server">
<HeaderTemplate>
<ul>
</HeaderTemplate>
<ItemTemplate>
<li>
<uc1:WebUserControl Text='<%# Container.DataItem %>'
ID="WebUserControl1" runat="server" />
</li>
</ItemTemplate>
<FooterTemplate>
</ul>
</FooterTemplate>
</asp:Repeater>
</div>
</form>
</body>
</html>


your parent page code-behind :
--------------------------------

protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
ArrayList values = new ArrayList();

values.Add("Apple");
values.Add("Orange");
values.Add("Pear");
values.Add("Banana");
values.Add("Grape");

Repeater1.DataSource = values;
Repeater1.DataBind();
}

}


WebUserControl .ascx :
--------------------------

<span>Fruit is :</span> <asp:TextBox ID="TextBox1"
runat="server"></asp:TextBox>


WebUserControl .cs code behind :
--------------------------

protected void Page_Load(object sender, EventArgs e)
{
// code for page load here
}

public string Text
{
get { return TextBox1.Text; }
set { TextBox1.Text = value; }
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,756
Messages
2,569,533
Members
45,006
Latest member
LauraSkx64

Latest Threads

Top