Include User Control in Repeater Control

W

Willy

Hi There!

Is there any way to include a User Control (ASCX) in the <ItemTemplate> of
the ASP.NET Repeater control? To be more exact, I need to include a user
control AND set some properties of the control based on the binded data.

For example...

<asp:Repeater id="Repeater1" runat="server">
<ItemTemplate>

<%#DataBinder.Eval(Container.DataItem,
"UserID")%> <br/>

<MyControls:UserControl1 id="UserControl1"
runat="server" TestProperty="" />

<%#DataBinder.Eval(Container.DataItem,
"ProductID")%> <br/>

</ItemTemplate>
</asp:Repeater>

I need to set the "TestProperty" of the UserControl1 based on binded data to
the Repeater control.

Is that possible? If so how do I do that?

Thank you all in advance!!!

willy
 
S

Scott Allen

Hi Willy:

You can override the ItemDataBound event, obtain a reference to the
nested control using the FindControl method, and once you have a
reference you can programatically set properties on the control.

Here is an example with a DropDownList and a DataGrid, which follows
the same plan:

http://odetocode.com/Articles/231.aspx

HTH,
 

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,774
Messages
2,569,596
Members
45,141
Latest member
BlissKeto
Top