Include User Control in Repeater Control

  • Thread starter Thread starter Willy
  • Start date Start date
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
 
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,
 
Back
Top